Questions tagged [array-push]

array-push refers to the javascript Array.prototype.push() method. The push() method adds one or more elements to the end of an array and returns the new length of the array.

refers to the javascript Array.prototype.push() method.

The push() method adds one or more elements to the end of an array and returns the new length of that array. developer

Example

var a = []; //or new Array()
var i = a.push('foo', 'bar');
console.log(i, a); 

the console will display the values

2 ["foo", "bar"]

The counterpart to push() is pop(), which removes the last item from an array.

Documentation

382 questions
-1
votes
1 answer

Difference between assignment and array_push in PHP in a foreach loop

I'm trying to understand the difference between array push and assign a value to the array with the equal sign in a foreach loop. Here's my problem: $data['database'] = array(); if ($sql->num_rows() > 0) { …
user6818018
-1
votes
1 answer

PHP push new data into given array

I may seem having difficulty in understanding on how array works. So result, I can't work on the issue. foreach($results as $key => $value){ $product_key = array( 'key' => $key ); array_push($results,…
Emjey23
  • 339
  • 1
  • 4
  • 16
-1
votes
3 answers

PHP Pushing variables to array1 then push it to array2 in a loop

I am having trouble to get the target result of an array. What I am trying to do is: push every variables in $inner_data in every loop. then push that $inner_data to $details_data to create an array inside an array I hope I explain my idea and…
Emjey23
  • 339
  • 1
  • 4
  • 16
-1
votes
1 answer

Node js async convert to sync

I need to push data to array synchronously. First API request get image key base one that need to get image data within loop. var deasync = require('deasync'); router.get('/a', function(req, res) { var username="user"; …
-1
votes
1 answer

How to array_push unique values inside another array

I have two arrays: $DocumentID = array(document-1, document-2, document-3, document-4, document-5, document-4, document-3, document-2); $UniqueDocumentID = array(); I want to push the unique objects inside of $documentid array…
UmarAbbasKhan
  • 91
  • 1
  • 12
-1
votes
1 answer

Array push to multidimensional array for JSON

Can someone pls help me on how to array_push to a multidimensional array. This is my code for pushing. $arrDataChart3["categories"] = array(); array_push($arrDataChart3["categories"], array( "category"=>array…
-1
votes
3 answers

Array push rows from SQL query

I am trying to save the rows (results) from an SQL query to a csv file. I am using array push in order to put the results in a list. Later I put the data from this list to my csv file. My code : while ($row = $query->fetch_assoc()) { …
Datacrawler
  • 2,780
  • 8
  • 46
  • 100
-1
votes
1 answer

how to use array_push php

Function result is not expected. I would like json encode type records function aTree($array, $treeList) { foreach ($array as $key => $value) { if (is_array($value) && !empty($value)) { $valueX =…
Ömer
  • 121
  • 1
  • 4
  • 19
-1
votes
1 answer

how to use array_push with multidimensional array with a class instanciation and how to deal with the id of the array

hi i'am using a mvc structure for my web site, i have a class that contains a multidimensional array with a class instanciation in it like this: protected $db; /* Construit une instance avec 4 poèmes. */ public function __construct() { …
-1
votes
1 answer

array_push into a multidimensional array (append a value to cell)

This is my code : $cars = array( array("Volvo" , '22,18,'), array("BMW" , '15,13'), array("Saab", '5,2' ), array("Land Rover", '17,15' ) ); print_r($cars); this is the output : Array ( [0] => Array ( [0] => Volvo [1] => 22,18, )…
iprophesy
  • 175
  • 3
  • 9
-1
votes
1 answer

Create Multidimensional Array

I have a function that is currently echoing image urls.. guid; } ?> Which gives me the following…
fightstarr20
  • 11,682
  • 40
  • 154
  • 278
-1
votes
2 answers

How do I correct this error: array_push() expects parameter 1 to be array, null given in?

I don't know enough about php to understand how to fix this. I've tried for the entire day and still can't fix it. I'm assuming this is an easy fix for those knowledgeable about php. I've read the other responses to similar questions, I've tried…
user3993907
  • 11
  • 1
  • 1
-1
votes
1 answer

array_push with associative array results in a multidimentional array

I have the following function which does some stuff and returns an array: function do_work($array){ $result = array(); array_push($result, array("HAHAHAH" => "looooooool")); foreach($array as $key=>$val){ …
Dumbo
  • 13,555
  • 54
  • 184
  • 288
-1
votes
1 answer

PHP Insert key into a multidimensional array

I created an empty array ($results) in which I store the data which I get back from the foreach loop. I do this for each search_tags keyword which I set up in an array. It all works, except I want to add the tag ($tag) which has been used to get…
-1
votes
3 answers

Array Push a Multi Dimentional Array

trying to add the array below into an existing one with array_push: 'tax_query' => array( 'relation' => 'and', array( 'taxonomy' => 'type', 'field' => 'slug', 'terms' => 'national' ) …
Codex73
  • 5,690
  • 11
  • 56
  • 76