How can I edit this foreach loop so that I will be able to use strpos
to look if q
is found in the label
?
The result array will contain those values.
$q
may be anna
or ann
or reas john
<?php
$q = $_GET["q"];
if (!$q) return;
$data = Array(
Array(
'label' => 'anna c13',
'category' => 'Products'
),
Array(
'label' => 'anders andersson',
'category' => 'People'
),
Array(
'label' => 'andreas johnson',
'category' => 'People'
)
);
$result = array();
foreach ($data as $value) {
array_push($result, array(
"label" => $value["label"],
"category" => $value["category"]
));
}
$json = json_encode($result);
echo $json;
?>
$key
contains a numeric index and$value
contains an array. But, I'm not sure what you're trying to do? Convert a list oflabels
andcategories
into a JSON ofnames
andemails
? Where are the email address supposed to come from? – Paulpro Aug 1 '11 at 18:14$result
array look like? – Shef Aug 1 '11 at 18:18q
is found in thelabel
. – Xalloumokkelos Aug 1 '11 at 18:23$q
may beanna
orann
orreas john
– Xalloumokkelos Aug 1 '11 at 18:52