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

How to properly use array_key_exists

$array = json_decode('[{"1234567":1368356071},{"7654321":1368356071}, etc, etc]'); $array2 = array(array(1234567 => time()), array(7654321 => time())); foreach($array2 as $key){ if(!array_key_exists(key($key),$array)) …
GameDevGuru
  • 1,095
  • 2
  • 12
  • 27
0
votes
3 answers

PHP array_push() without ordering

I am using the array_push() method to insert ids from my database. Example: print_r($arr_usr_ids); Array ( [0] => 34 [1] => 35 [2] => 34 [3] => 37 [4] => 38 [5] => 30 ... ) $arr_usrs = array(); foreach($arr_usr_ids as $key => $value)…
Jim
  • 923
  • 4
  • 17
  • 30
0
votes
2 answers

array_push() expects parameter 1 to be array

I have a PHP problem. I have this code block $arr_foundits = array(); foreach($its as $it){ //print_r($it); $post_categories = wp_get_post_categories( $it->ID ); $cats = array(); foreach($post_categories as $c){ $cat =…
digitalzoomstudio
  • 1,112
  • 1
  • 15
  • 30
0
votes
2 answers

array_push multiple values based on variable?

I am trying to create an array with values repeated according to some variables. In this scenario: $slipszero = "2" & $slipsone = "1", and those values can change. This is my code as of now: $problist = array(); foreach ($rows as $value) { …
David
  • 1,175
  • 1
  • 16
  • 29
0
votes
2 answers

PHP, How to push elements into this array?

Example array: $r["NO"] = array( "hello" => "hey", "hey" => array("oij", "ioj"), "hola" => "hia" ); How can I add "blabla" => "hey" Now in the bottom of that array? End result should be: $r["NO"] = array( "hello" => "hey", "hey" => array("oij",…
Kristian Rafteseth
  • 2,002
  • 5
  • 27
  • 46
0
votes
1 answer

How to push an array in a for-loop statement, in ActionScript

I'm sorry if I'm being vague in any way as I'm nooby at AS3.0 and stackoverflow. I simply wanna push the i variable to add to the variable _bullets. var i:int = 0; //initializing the i variable _bullets.push(i); //Loops thought all the bullets on…
0
votes
2 answers

MySQL and push query array together

I have this code here $sql_array = array(); if($result['user_id'] == 'OA'){ $sql = "select distinct id, FirstName, LastName from table_one ti left join table_two sp on (sp.user_id = ti.id) or (sp.user_id = ti.id)"; …
user1269625
  • 3,121
  • 26
  • 79
  • 111
0
votes
1 answer

Extending basic Javascript Cart to be multi dimensional

I'm trying to do a 'quick' javascript shopping cart as a proof of concept by extending this nice little demo. http://www.99points.info/2010/12/ajax-shopping-cart-with-jquery-and-php/ I'm trying to extend into this the concept of item 'types' in the…
0
votes
2 answers

PHP array_push doesn't work with jquery $_REQUEST object

At http://maureenmoore.com/momp_112412/112412.html I am trying to make an array of the divs that were dragged into the droppable box. Please see the view source. I use $.post to send the divs to the php file process.php and it gives me 1 to 3…
Maureen Moore
  • 1,049
  • 2
  • 9
  • 21
0
votes
1 answer

Javascript - Array push for AutoComplete

I am working on a AutoComplete search bar that reads from an array. I am needing to parse a JSON file and push the names into an array. I have everything working except for the right command to push to the actual array. What would I use to push to…
Dan Rivers
  • 173
  • 3
  • 14
0
votes
5 answers

Assigning indexes to subarrays

I need help figuring out how to assign an index to subarrays. Here is what I have so far: I start off by setting up the array with the first subarray and some data. $start=array(array($rand, $_POST['day'], $_POST['time'], $delay)); Then when I need…
tsieber
  • 3
  • 1
0
votes
1 answer

Questions about actionscript

I have a few different question and i have decided to put them in one. So the first question : If i have one and the same code(for example): buttonsA.buton1a.addEventListener(MouseEvent.MOUSE_DOWN ,…
Yoan Dinkov
  • 531
  • 1
  • 5
  • 17
0
votes
1 answer

php inject value to inner array's specific item

I would like to insert value to an array's inner arrays specific item. So I have an array which is loosing data between functions which I can't finde where and when it should be printed out some values are missing, but I can get these values from an…
Laci K
  • 585
  • 2
  • 8
  • 24
0
votes
1 answer

array_push not working in foreach loop

I have encountered a problem when trying to add values to an array through a foreach loop. Basically I have this form where there's a bunch of topics that the user can click 'like' or 'dislike' on with two radio-buttons per topic. I then want to…
DannyCruzeira
  • 564
  • 1
  • 6
  • 19
0
votes
1 answer

How do you using $_POST values to create an associative array

I am trying to divide $_POST values into different arrays to check its values. I am trying to retain both the $key and $values as an associative array. For now, only array_push works, but not array_merge. Array_merge returns an empty array for me.…
user1187135