Reputation: 365
I currently get back data from an API in an array like:
Array ( [Play] => 0,0
[SE] => 10,10
[AW] => 1,1
[ID] => 2949038,2947560
[status] => 1
[Name] => txt1,txt2 ) 1
To get the ID values I just use a basic foreach:
$ids = explode(',', $userQrLt['ID']);
foreach($ids as $id) {
echo "http://thewebsite.com/cgi-bin/zd_view.cgi?q=" . $id . "<br />";
}
I also need the "Name" values, the ids are in order, meaning, 2949038 goes with txt1 and 2947560 goes with txt2, I know I could do another for each, but is there a way I could grab both values with the 1 for each?
Thanks for any help guys!
Upvotes: 0
Views: 259
Reputation: 2327
I suggest you the for
loop
$ids = explode(',', $userQrLt['ID']);
$names = explode(',', $userQrLt['Name']);
foreach($i=0;$i<count($ids);$i++) {
echo "http://thewebsite.com/cgi-bin/zd_view.cgi?q=".$ids[$i]."&name=$names[$i]<br />";
}
Upvotes: 0
Reputation: 2897
Sure, with foreach you can also grab the index, and use it to get the other part:
$ids = explode(',', $userQrLt['ID']);
$names = explode(',', $userQrLt['Name']);
foreach($ids as $index => $id) {
$name = $names[$index]; // but not sure what you want to do with it..
echo "http://thewebsite.com/cgi-bin/zd_view.cgi?q=" . $id . "<br />";
}
Upvotes: 6