php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #55806 preg_grep( )function is giving result but not valid
Submitted: 2011-09-28 14:04 UTC Modified: 2011-12-03 22:48 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: engrfawadghafoor at gmail dot com Assigned:
Status: No Feedback Package: Output Control
PHP Version: 5.3.8 OS: windows 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
42 - 29 = ?
Subscribe to this entry?

 
 [2011-09-28 14:04 UTC] 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>";






Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-09-28 14:29 UTC] 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-12-03 22:48 UTC] frozenfire@php.net
-Status: Open +Status: No Feedback
 [2011-12-03 22:48 UTC] frozenfire@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 20:01:28 2024 UTC