Im having following 2 functions repeat1 and repeat2.
In the first case,i have an array which is suppose to return 2 values.one is the number of matched values and the other one is the contents of match[0].But im not getting the reuqire output.I have displayed the ouput that i am getting.The desired output is displayed in the end.Kindly help
Code: Select all
<?php
echo "function repeat1" . "<br/>";
function repeat1($reg,$search)
{
$result1=preg_match_all($reg,$search,$match);
if ($result1==0)
{
$output= "value not found";
}
else
{
//echo "preg_match:result not found";
$output="value found";
}
echo "repeat1:" .$output;
//return $match[0];
$retarray=array($result1,$match[0]);
return $retarray;
}
$assign=repeat1("/[a-z]/","asfaqwqeq");
echo "<br/>";
foreach($assign as $disp)
{
echo "return from repeat1:".$disp . "<br/>";
}
Code: Select all
echo "function repeat2" . "<br/>";
function repeat2($reg,$search)
{
$result1=preg_match_all($reg,$search,$match);
if ($result1==0)
{
$output= "value not found";
}
else
{
//echo "preg_match:result not found";
$output="value found";
}
//return $match[0];
echo "repeat2:" .$output . "<br/>";
return $match[0];
}
$assign=repeat2("/[a-z]/","asfaqwqeq");
foreach($assign as $disp)
{
echo "return from repeat2:".$disp . "<br/>";
}
?>
Output1:
function repeat1
repeat1:value found
return from repeat1:9
return from repeat1:Array
Output2
function repeat2
repeat2:value found
return from repeat2:a
return from repeat2:s
return from repeat2:f
return from repeat2:a
return from repeat2:q
return from repeat2:w
return from repeat2:q
return from repeat2:e
return from repeat2:q
This is what i require
From the first function ,i need the following output:
function repeat1
repeat1:value found
return from repeat1:9
return from repeat1:a
return from repeat1:s
return from repeat1:f
return from repeat1:a
return from repeat1:q
return from repeat1:w
return from repeat1:q
return from repeat1:e
return from repeat1:q
i.e the main problem am having is that am unable to display the value of match[0] in function
repeat1