Doc #55806 [NEW]: preg_grep( )function is giving result but not valid

From: Date: Wed, 28 Sep 2011 14:04:43 +0000
Subject: Doc #55806 [NEW]: preg_grep( )function is giving result but not valid
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-7274@lists.php.net to get a copy of this message
From: Operating system: windows 7 PHP version: 5.3.8 Package: Output Control Bug Type: Documentation Problem Bug description:preg_grep( )function is giving result but not valid Description: ------------ --- From manual page: http://www.php.net/function.preg-grep --- Test script: --------------- $var = ucfirst ($_REQUEST['queryString']); $friends_inner=$_SESSION['friends']; for($i=0; $i<sizeof($friends_inner); $i++) { $selected_friend=$friends_inner[$i]; $selected_friend_id=$selected_friend['id']; //array of ids $selected_friend_name=$selected_friend['name']; // array of names $name[$i]=$selected_friend_name; } $result=preg_grep('/^'.$var.'.*/', $name); (to be note) this will show different result echo "total elements in matched array name = ".count($result)."<br>"; $final_result=array(); $maxindex = array_pop(array_keys($result)); for($i=0;$i<=$maxindex;$i++){ //returns array that start with zero if(isset($result[$i])){ array_push($final_result,$result[$i]); } } $ids_of_result=array(); function sort_arrays($final_result,$friends_inner) { $ids_of_result = array(); foreach($final_result as $fnl_rslt){ foreach($friends_inner as $frnd_in){ if($fnl_rslt == $frnd_in['name']){ //echo 'Name : '.$frnd_in['name'].'<br>'; //echo 'Id : '.$frnd_in['id'].'<br>'; array_push($ids_of_result,$frnd_in['id']); } } } return $ids_of_result; } $ids_of_result = sort_arrays($final_result,$friends_inner); (to be note) this will show different result echo "total elements in match array ids = ".count($ids_of_result)."<br>"; -- Edit bug report at https://bugs.php.net/bug.php?id=55806&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=55806&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=55806&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=55806&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=55806&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=55806&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=55806&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=55806&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=55806&r=needscript Try newer version: https://bugs.php.net/fix.php?id=55806&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=55806&r=support Expected behavior: https://bugs.php.net/fix.php?id=55806&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=55806&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=55806&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=55806&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=55806&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=55806&r=dst IIS Stability: https://bugs.php.net/fix.php?id=55806&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=55806&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=55806&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=55806&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=55806&r=mysqlcfg

« previous php.doc.bugs (#7274) next »