1

I'm trying to populate all the links in my database into an array with a key something like this:

$link = array(99999 => "http://link1.com", 111111 => "http://link2.com");

Which returns:

Array ( [99999] => http://link1.com [111111] => http://link2.com )

How can i get the array to look like that when going through a loop, Here is my code:

while($row = mysql_fetch_array($query)) {
    $link[] = "$row[r_id] => $row[r_link]";
}

It returns:

Array ( [0] => 24004 => http://link1.com [1] => 30554 => http://link2.com

But i don't wan't it to be like this, How can i get it the same as the first example while going through a loop ?

3
  • "with a key something like this" - your description couldn't be more vague than that... Commented Feb 1, 2014 at 12:04
  • Well the top bit is what i want it to look like, But mine is looking like the bottom code when going through a loop. Commented Feb 1, 2014 at 12:06
  • you know, if you have picked the same numbers, it would have made a lot more sense... Commented Feb 1, 2014 at 12:08

2 Answers 2

1
while($row = mysql_fetch_array($query)) {
    $link[$row['r_id']] = $row['r_link'];
}
Sign up to request clarification or add additional context in comments.

1 Comment

@user3173526 what about accepting EricSchaefer's answer then?
0
$link[$row['r_id']] = $row['r_link'];

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.