Jump to content

array_push queries


genzedu777

Recommended Posts

Hi,

 

I need some help in understanding this coding

 

$data=mysqli_query ($dbc,$query);

$topicIDs = array();

while ($row = mysqli_fetch_array($data)) {

    array_push($topicIDs, $row['topic_id']);

 

For $topicIDs = array(), my understanding is, it is meant to clear or empty any arrays that is in the $topicIDs variable? Am I right?

 

array_push($topicIDs, $row['topic_id']);.

I am really confused in this portion. Is $row['topic_id'] value stored in $topicIDs?

 

Thanks,

Wilson

Link to comment
https://forums.phpfreaks.com/topic/202623-array_push-queries/
Share on other sites

For $topicIDs = array(), my understanding is, it is meant to clear or empty any arrays that is in the $topicIDs variable? Am I right?

Pretty much.  It assigns an empty array to $topicIDs.  If anything was there before (whether an array or a scalar) it is lost.  If it did not exist before, it will now.

 

array_push($topicIDs, $row['topic_id']);.

I am really confused in this portion. Is $row['topic_id'] value stored in $topicIDs?

That adds the value in $row['topic_id'] on to the end of the array ($topicIDs).  It is the same as $topicIDs[] = $row['topic_id']

Link to comment
https://forums.phpfreaks.com/topic/202623-array_push-queries/#findComment-1062120
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.