Hello i got a problem, i have created costum array search function
the problem is function will ignore first item in array
if i try to find for example 'Router' everything works as expected but if i wan't to find 'App' the function will return false as value do not exist in array
http://easycaptures.com/fs/uploaded/874/4316690019.png
http://easycaptures.com/fs/uploaded/874/5374100107.png
full code
edit:
Anyway i fixed it for got to add loop break
http://easycaptures.com/fs/uploaded/874/9716920288.png
PHP Code:
function array_find($find,array $array,$return = ARRAY_FIND_RETURN_BOOL)
{
$result = false;
foreach($array as $index => $value)
{
if(is_array($value) == true)
{
$result = array_find($find,$value,$return);
if($result == false)
{
continue;
}
}
else
{
if($value == $find)
{
if($return == ARRAY_FIND_RETURN_BOOL)
{
$result = true;
}
elseif($return == ARRAY_FIND_RETURN_ARRAY)
{
$result = $array;
}
else
{
$result = $index;
}
break;
}
}
}
return $result;
}
PHP Code:
$testArray = array(
0 => array
(
'Name' => 'App',
'Class' => 'System\Application',
'Enabled' => 1
),
1 => array
(
'Name' => 'Router',
'Class' => 'System\Components\Router',
'Enabled' => 1
),
);
http://easycaptures.com/fs/uploaded/874/4316690019.png
http://easycaptures.com/fs/uploaded/874/5374100107.png
full code
PHP Code:
define('ARRAY_FIND_RETURN_INDEX', 2);
define('ARRAY_FIND_RETURN_ARRAY', 3);
define('ARRAY_FIND_RETURN_BOOL', 4);
function array_find($find,array $array,$return = ARRAY_FIND_RETURN_BOOL)
{
$result = false;
foreach($array as $index => $value)
{
if(is_array($value) == true)
{
$result = array_find($find,$value,$return);
if($result == false)
{
continue;
}
}
else
{
if($value == $find)
{
if($return == ARRAY_FIND_RETURN_BOOL)
{
$result = true;
}
elseif($return == ARRAY_FIND_RETURN_ARRAY)
{
$result = $array;
}
else
{
$result = $index;
}
break;
}
}
}
return $result;
}
$testArray = array(
0 => array
(
'Name' => 'App',
'Class' => 'System\Application',
'Enabled' => 1
),
1 => array
(
'Name' => 'Router',
'Class' => 'System\Components\Router',
'Enabled' => 1
),
);
echo '<b>array_find</b><br>';
echo 'Find value "Router" :: Mode ARRAY_FIND_RETURN_ARRAY<pre>'.var_export(array_find('Router',$testArray,ARRAY_FIND_RETURN_ARRAY),true).'</pre>';
echo 'Find value "Router" :: Mode ARRAY_FIND_RETURN_BOOL<pre>'.var_export(array_find('Router',$testArray,ARRAY_FIND_RETURN_BOOL),true).'</pre>';
echo 'Find value "Router" :: Mode ARRAY_FIND_RETURN_INDEX<pre>'.var_export(array_find('Router',$testArray,ARRAY_FIND_RETURN_INDEX),true).'</pre>';
echo '<b>Actual Array</b><br>';
echo '<pre>'.var_export($testArray,true).'</pre>';
Anyway i fixed it for got to add loop break
PHP Code:
if($result == false)
{
continue;
}
else
{
break;
}