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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: engrfawadghafoor at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Sat Dec 21 15:01:29 2024 UTC