PHP Classes

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Classes of Horse Luke  >  Array Picker  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example
Class: Array Picker
Filter arrays by key, exclude items or match rules
Author: By
Last change:
Date: 1 year ago
Size: 2,063 bytes


Class file image Download

require dirname(__FILE__). '/lrn_tool_array_picker.php';

$data = array('s'=>1, 's2'=>2, 's3'=>3);
$lrn_tool_array_picker = new lrn_tool_array_picker();

//[ENG]Simple method, only return specific index value from array
$result = $lrn_tool_array_picker->by_index($data, 's,s3');

//[ENG]Simple method, exclude specific index value from array
$result2 = $lrn_tool_array_picker->exclude_index($data, 's,s3');

//[ENG]Exclude or return specific index value from array by rule
[ENG]rules array or string. If it is string, use and delimiter(&) between rule.
Format of each rule:
    [path to array, delimited by "/". If next path is circular array or want to match any name of index, use "*" instead]/(_return|_return_exclude)=xx,xx,xx,xx,xx


$data3 = require dirname(__FILE__). '/raw_data.php';
$conds = array(
'/_return=users,total_number', //整个数组顶端仅保留users,total_number节点
'/users/*/_return=idstr,screen_name,created_at,status', //users节点下每个子数组,仅保留idstr,screen_name,created_at,status节点
'/users/*/status/_return=idstr,created_at,text,source,pic_urls', //users节点下、每个子数组中的status节点,仅保留idstr,created_at,text,source节点
'/users/*/status/_return_exclude=source,pic_urls', //users节点下、每个子数组中的status节点,去掉source,pic_urls节点
//$conds = implode('&', $conds); //此步可省略

$time_pass = microtime(true);
$result3 = $lrn_tool_array_picker->by_rule($data3, $conds);

echo (
microtime(true) - $time_pass) / 1;