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

Merge multidimensional arrays in PHP

I would like create a list of values within a new array based on the same keys from the previous array. Basically, I would like to turn this array: $old_array = Array ( [segment1] => Array ( [subsegment] => Array ( [number1] => 1413 …
TheBigDoubleA
  • 432
  • 2
  • 7
  • 26
0
votes
1 answer

Constructing multidimensional array in php

I need to construct this array: Array( [Creativo] => Array( [C1] => Array( [0] => O10 [1] => O11 ) [C2] => Array( [0] => O12 [1] => O13 [2] => O14 ) ) [Detallista] => Array( …
0
votes
2 answers

Populating dynamically-created arrays in PHP

I'm building a web-app that has a rather large (10K rows) reference table. Table reference has a category, id , description. As I'm using this reference a data a lot to fill drop-down boxes and such, I'm trying to put them in arrays. I had them in…
MarlonB
  • 63
  • 1
  • 6
0
votes
2 answers

How to add value to CodeIgniter query result?

I am using CodeIgniter to generate some query results, and then in a second step using a foreach loop to run a method using values from the query result. What I would like to do now is to somehow combine the new variable with the original query. …
DanielAttard
  • 3,467
  • 9
  • 55
  • 104
0
votes
1 answer

how to array_push a string into a multidimensional array

Here is the problem: $arr = array(array()); $arr[0]['a'] = 'for 0.a'; $arr[0]['b'] = 'for 0.b'; $arr[1]['a'] = 'for 1.a'; $arr[1]['b'] = 'for 1.b'; array_push($arr,'for 2.a'); array_push($arr,'for 2.b'); print_r($arr); String…
0
votes
1 answer

$array[] and array_push not working

I'm testing out a simple redemption system and it's not working. When a user enters a valid code, it doesn't add it to the 'used' array. Here is the full code:
0
votes
3 answers

array_push is replacing the variables instead of adding them to the end

array_push($info["First_Names"], "$fname"); array_push($info["Last_Names"], "$lname"); array_push($info["Gender"], "$gender"); Does anyone see an issue? Array push is just replacing variables instead of adding them. The variables of $fname, $lname,…
John AJ
  • 21
  • 1
  • 7
0
votes
3 answers

Javascript: Failing to add text into Array

The problem I am having is that my text is not being added into the array for some reason. The code looks fine, but I can confirm it's not being added by having it print out the array.length.