Jump to content

Array_search - finding first non-zero element?


rjt90

Recommended Posts

use array_filter

$array = array(0,0,0,0,0,1,2,3);

$found = array_filter($array);

echo '<pre>',print_r($found, true),'</pre>';

/** result
Array
(
    [5] => 1
    [6] => 2
    [7] => 3
)

*/

edit :

 

or

list($nonZeroKey,$value) = each(array_filter($array));

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.