Jump to content

Recommended Posts

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]foreach ($wcr[$i] as $key=>$value):
echo $key[$i];
endforeach;[/quote]
not works again : Invalid argument supplied for foreach()
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?=$i['country']?> [/quote] - get no results

What i need:
[code]<?=$wcr[$i['country']]?> [/code]- it gets value from array (i.e. Germany)
Need to get ONLY Array key. i.e number for Germany in array $wcr.

Then need no echo, i want to insert this varable into link
[code]<A href="http://someurl.com/search.php?from=0&amp;country=0"><?=$wcr[$i['country']]?></A>[/code]

Now country=0. need to change it, when country will change.
Link to comment
https://forums.phpfreaks.com/topic/9526-array-simply-question/#findComment-35210
Share on other sites

[!--quoteo(post=373248:date=May 11 2006, 06:55 AM:name=hvle)--][div class=\'quotetop\']QUOTE(hvle @ May 11 2006, 06:55 AM) [snapback]373248[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I suppose you have the country name, and you need to find out key location.

Here is one way to do it:

$country = "Germany"; // say you want to find key location for Germany

foreach ($wcr as $key=>$val)
{
if ($val == $country)
return $key;
}
[/quote]

Yes, you are right it so easy, but just courious - NOT WORKS :-( no results
Link to comment
https://forums.phpfreaks.com/topic/9526-array-simply-question/#findComment-35237
Share on other sites

[!--quoteo(post=373274:date=May 11 2006, 08:00 AM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ May 11 2006, 08:00 AM) [snapback]373274[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Why are you printing an entire array repeatedly that doesn't have ANYTHING to do with the foreach loop?
[/quote]
I don't know. ober please tell me what can i do?
Link to comment
https://forums.phpfreaks.com/topic/9526-array-simply-question/#findComment-35252
Share on other sites

so you want to print each key in the array? or do you want to print the key that matches a specific country?

to print each key, someone wrote this earlier with the wrong syntax

foreach($wcr as $key => $value){
echo $key."<br />";
}



to mactch simply provide the country

$country = "Albania";

foreach($wcr as $key => $value){
if($value == $country){
echo $key."<br />";
break; //im not too sure if you need it or if it works in this type of loop
}
}

Link to comment
https://forums.phpfreaks.com/topic/9526-array-simply-question/#findComment-35257
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.