简体   繁体   中英

Dynamic Content in PHP array

This should be a quick one.

I'm pulling a list of id's and I need to place them in an array.

Here is my php code to get the list of id's

$get_archives = mysql_query("SELECT * FROM archive WHERE user = '$email'  ");
while ($row = mysql_fetch_assoc($get_archives)) {
$insta_id = $row['insta_id'];

    $insta_id = "'" . $insta_id."',";

echo $insta_id;

    };

This echo's a list of id's that looks like this: '146176036','136514942',

Now I want to put that list into an array. So i tried something like this:

    $y = array($insta_id);

However that isn't working. Any suggestions?

$y = array();
while ($row = mysql_fetch_assoc($get_archives)) {
  $y[] = $row['insta_id'];
}
$myArray = array();

    $get_archives = mysql_query("SELECT * FROM archive WHERE user = '$email'  ");
    while ($row = mysql_fetch_assoc($get_archives)) {
    $insta_id = $row['insta_id'];

        $insta_id = "'" . $insta_id."',";


        $myArray[] =$insta_id;

        };

did you mean like this: ?

$insta_id=array();
while ($row = mysql_fetch_assoc($get_archives)) {
$insta_id[] = $row['insta_id'];
}

Create an array, and push the values into it:

$values = array();

while ( $row = mysql_fetch_assoc( $get_archives ) ) {
  array_push( $values, $row['insta_id'] );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM