tags:

views:

70

answers:

4

here is the code im having trouble with

$key = array(
"0" => "sss",
"1" => "wst",
"2" => "sfv",
"3" => "lac",
"4" => "sgv",
"5" => "lgb",
"6" => "ant"
);

$urls = array(
"0" => "http://www.sarmenhb.com/index.php?key=",
"1" => "http://www.navidoor.com/index.php?key=",
"2" => "http://www.worldexchange.com/index.php?key=",
"3" => "http://www.iaddesign.com/index.php?key=",
"4" => "http://www.iadesignandstudio.com/index.php?key=",
"5" => "http://www.redlineautoleasing.com/index.php?key="

);

for($a=0;$a <= count($urls);$a++) {
foreach($key as $keys) {
print $urls[$a].$keys[$a]."<br/>";

}
}

print "<br/><br/>";

i am trying to make the output look like this:

http://www.sarmenhb.com/index.php?key=sss
http://www.navidoor.com/index.php?key=sss
http://www.worldexchange.com/index.php?key=sss
http://www.iaddesign.com/index.php?key=sss
http://www.iadesignandstudio.com/index.php?key=sss
http://www.redlineautoleasing.com/index.php?key=sss

http://www.sarmenhb.com/index.php?key=wst
http://www.navidoor.com/index.php?key=wst
http://www.worldexchange.com/index.php?key=wst
http://www.iaddesign.com/index.php?key=wst
http://www.iadesignandstudio.com/index.php?key=wst
http://www.redlineautoleasing.com/index.php?key=wst

etc including all key values included as a value the the param key

ive removed the origional urls to prevent url hacking but how can i print an output like that?

the output i keep getting is key=s or key=w the whole key value isnt displaying. along with an error of Notice: Uninitialized string offset: 3 in D:\wamp\www\MVC\t.php on line 32

please help

thank alot!

+3  A: 
foreach($key as $string)
{
    foreach($urls as $address)
    {
        echo $address . $string . "<br/>";
    }
}
Chacha102
whoa makes sense. i feel such an idiot for including the key values inside the foreach arrays.. thanks alot
If my answer solved your problem, click the checkmark to mark it as the accepted answer.
Chacha102
This answer is sufficient, but does it really need 3 upvotes?
Antony Carthy
If people like the answer sure. I don't care because I've already hit my cap.
Chacha102
A: 

That's because you're printing $keys[$a]. $keys is a string from your array, and $a would just get a single character. You can select characters in strings the same way you select variable from array.

If you remove the square brackets it should work.

print $urls[$a].$keys."<br/>";
peirix
+2  A: 

I would simply do two foreach statements:

foreach($urls as $url) {
  foreach($keys as $key) {
    print $url.$key."\n";
  }
}

I also recommend you to pluralize the name of your arrays for simple readability, check the output here.

CMS
A: 

Remove the foreach loop and change $keys[$a] to $key[$a].

ian