Doc #55806 [Opn->NoF]: preg_grep( )function is giving result but not valid
| From: | frozenfire@php.net | Date: | Sat, 03 Dec 2011 22:48:27 +0000 |
| Subject: | Doc #55806 [Opn->NoF]: preg_grep( )function is giving result but not valid | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-7526@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=55806&edit=1
ID: 55806
Updated by: frozenfire@php.net
Reported by: engrfawadghafoor at gmail dot com
Summary: preg_grep( )function is giving result but not valid
-Status: Open
+Status: No Feedback
Type: Documentation Problem
Package: Output Control
Operating System: windows 7
PHP Version: 5.3.8
Block user comment: N
Private report: N
New Comment:
It's been two months now. I don't think we're going to get the feedback we need.
If feedback is provided, reopen the bug.
Previous Comments:
------------------------------------------------------------------------
[2011-09-28 14:29:03] rquadling@php.net
Can you provide a cleaner example, showing the data you are using and the expected
and actual results please? Your test script is specific to your requirements and
your data.
------------------------------------------------------------------------
[2011-09-28 14:04:42] engrfawadghafoor at gmail dot com
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 this bug report at https://bugs.php.net/bug.php?id=55806&edit=1