Jan Dragsbaek
Jan Dragsbaek

Reputation: 8101

PHP equivalent of $array[] in javascript

I am trying to pass an arbitrary amount of arrays from my javascript to a php file with json through ajax, the problem word is arbitrary, assume following allmost-development-code

var arrayContaingAll;

$("li", "#list").each(function()
{
  var a = array( $(".name",this).val(), $(".unit",this).val(), $(".amount", this).val() );
  arrayContainingAll[] = a;
});

however, the [] functionality on an array does not work for me, how would i go around implementing such feature?

Yes, i know PHP damaged me thinking that way

Upvotes: 1

Views: 462

Answers (2)

Praveen Prasad
Praveen Prasad

Reputation: 32117

var arrayContaingAll=[];

$("li", "#list").each(function()
{
  var tempArray=[];
  tempArray.push($(".name",this).val());
  tempArray.push($(".unit",this).val());
  tempArray.push($(".amount",this).val());
  arrayContainingAll.push(tempArray);
});

//arrayContaingAll is ready

//to optimize ur code you may cache li like this inside each

var li= $(this);
tempArray.push(li.find('class_Name'));

Upvotes: 2

KJYe.Name
KJYe.Name

Reputation: 17169

arrayContainingAll.push(a); //equavalent in JavaScript to PHP's arrayContainingAll[] = a;

Upvotes: 5

Related Questions