what do i need to change for my codes?
the echo is just 1 letter m
this is my code :
$string = 'mars@email.com,123,12,1|art@hur.com,321,32,2';
$output = array();
foreach (explode('|', $string) as $key => $person) {
$output[] = array(
'email' => $person[0],
'score' => $person[1],
'street' => $person[2],
'rank' => $person[3]
);
echo $output[0]['email'];
}
OUTPUT : m
the output should be:
$email1 = mars@email.com
$score1 = 123
$street1 = 12
$rank1 = 1
$email2 = art@hur.com
$score2 = 321
$street2 = 21
$rank2 = 2
is it possible to do this code to output the email1 and email2?
is my code correct or do i need to change something?
thank you.
You need to use a nested loop; the first to iterate over the pipe delimited data and the second for the comma delimited entries.
Example here – http://codepad.viper-7.com/82HbtT