Reputation: 1
i am having one key list for example
$key_list=array("list"=>array("task","duration"));
function array_key_fun($key_list,$test_input){
//(is_array($test_input)){
return array_map('myfunction',$test_input,$key_list);
//}
}
//$va=array_map("myfunction",$test_input);
//print_r(array_key_fun($key_list,$test_input));
function myfunction($arr)
{
if(is_array($arr))
{
$get_array= get_childs($arr);
return $get_array;
}
}
function get_childs($arr){
$newarr=array();
$newarr_en='';
foreach($arr as $key=>$value)
{
if(is_array($value)){
$newarr[$key]=get_childs($value);
}else{
if (in_array($key,$key_list)) //here im facing the problem with key_list
{
..............
}
else
{
...............
}
}
}
return $newarr;
}
Upvotes: 0
Views: 1189
Reputation: 86406
Either pass in function or declare as global
function abc($a,$key_list){
OR
function abc($a){
global $key_list;
//rest of code
EDIT:
When you pass the array as parameter of function you have to pass the value in call as well
when you call this function this should be
//array should be declared before calling function
$key_list=array("list"=>array("task","duration"));
abc($a,$key_list); //pass this array
Upvotes: 2
Reputation: 57268
You have to bring the variable into scope, within your code you have .........
if you replace that with global $key_list
this will allow the function to Read / Write to that stack.
Upvotes: 0
Reputation: 16845
http://php.net/manual/en/function.array-walk.php
array_walk
try this
Upvotes: 1