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
3
votes
2 answers

PHP fill up an associative array

I'm creating a data.php file which returns a json file to a html file where I fill up a grid with the data from the data.php file. I need this to be an associative array in the following form: [ {"CompanyName":"Alfreds…
3
votes
1 answer

array_push not working in foreach loop

print_r($members) coming like this following result Array ( [myname] => Array ( [userid] => 52 [age] => 46 ) Array ( [hisname] => Array ( [userid] => 22 [age] => 47 ) Array ( [yourname] => Array ( [userid] => 47 [age] => 85 ) array_push() push not…
Mo.
  • 26,306
  • 36
  • 159
  • 225
3
votes
6 answers

Append keys to existing array value

I have the following array and by using array_push & I am getting not the right result. Array: Array ( [0] => 1039 [1] => 417 [2] => 418 ) Array Push: array_push($array, array("a","b","c")); Result: Array ( [0] => 1039 [1] =>…
Bas
  • 33
  • 3
3
votes
5 answers

Make new array from specifed string?

I have this kind of simple array: $puctures=array('1_noname.jpg','2_new.jpg','1_ok.jpg','3_lets.jpg','1_stack.jpg','1_predlog.jpg','3_loli.jpg'); I want to make new array that i will only have elements thats starts with 1_…
Miomir Dancevic
  • 6,726
  • 15
  • 74
  • 142
3
votes
3 answers

Why cant i push element onto sub array in foreach loop?

I'm trying to understand something about arrays in for each loops that might be obvious to many. When i loop through my multi-dimensional array, i attempt to find sub arrays with no third element. If they have no third element, i want to add a third…
jreidko
  • 77
  • 1
  • 7
3
votes
1 answer

Php pass array to JSON

I have a PHP file that create an array of class with array_push and I need to convert this array to JSON format. The array is created perfect but when I try to encode to JSON the value returned is an array of empty elements. the code of php: $return…
Frab Lopez
  • 103
  • 1
  • 3
  • 10
2
votes
2 answers

How Do i use array_push in foreach loop PHP?

Here is example which I have try load("

Heading 1

This heading 2

"); $e = $html->find("h2", 0); $key =…
Seek Php
  • 163
  • 2
  • 3
  • 12
2
votes
4 answers

php add key with value to array faster way

I have an array: $data = array( 'loggedin' => false ); i want to add other keys as well their values if the user is logged in so i use: if ( $this->auth_model->loggedin()){//user is logged in $data["loggedin"] =…
stergosz
  • 5,754
  • 13
  • 62
  • 133
2
votes
1 answer

Nested Key-Value lookups in php

I am trying to make a "stock" website for a class at school, and it's my first dive into php. Basically, the script pulls down a CSV file form a google docs spreadsheet, and (attempts) to put the values into an array for use later. I'd like to show…
nlowe
  • 999
  • 4
  • 11
  • 26
2
votes
2 answers

(PHP) $_POST + cURL + multi array

I try to send a multi array via cURL but I can't find a nice way to do it. My code example: $data = array( 'a' => 'testa', 'b' => 'testb', 'c[d]' => 'test1', 'c[e]' => 'test2' ); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); This will work and give…
Talisin
  • 614
  • 1
  • 6
  • 17
2
votes
1 answer

How to put loop array inside another array

line 1: "item_details" => array( array( $item_details, ), ), line2: $item_details; foreach(Cart::content() as $item) { $item_details = array_push( array ( …
2
votes
3 answers

How to use array_push to add value and key to array

I am receiving an error once this code runs. I have looked up possible solutions but everything seems to be formatted correctly. $searched = 'searched'; $count = '59'; $prop = Array(); $i = 0; while ($i++ <= 4) { array_push($prop[$i]…
Tj tarmon
  • 35
  • 1
  • 1
  • 4
2
votes
1 answer

Push key value in empty array using php

I have associative array and value related with that key contain json_encoded data so I converted it and it resulted in array,I am using array_walk to iterate each array value than and printing values using foreach loop but at same time I want to…
user_1234
  • 741
  • 1
  • 9
  • 22
2
votes
1 answer

How to push array elemnt to specific position in another array using php

I want to push new array to another array at specific position for this purpose I used array_splice followed some stackoverflow links but it didn't work for me I refered this links also but they mentioned only for single value not array. How to…
user_1234
  • 741
  • 1
  • 9
  • 22
2
votes
1 answer

PHP array_push() - pushing new data to array

I have an array which looks like this: Array ( [0] => Array ( [1] => Array ( [name] => vrij // ... ) [2] => Array ( …
Joris Ooms
  • 11,880
  • 17
  • 67
  • 124
1 2
3
25 26