2

I have array in Angular JS:

$scope.formData.conditions

Before AJAX request I display this varaible:

[1: "1", 2: "2", 3: "3", 4: "4", 5: "5"]

But on server PHP I get array like as:

["conditions"]=>
  array(6) {
    [0]=>
    string(0) ""
    [1]=>
    string(1) "1"
    [2]=>
    string(0) ""
    [3]=>
    string(1) "3"
    [4]=>
    string(1) "4"
    [5]=>
    string(1) "5"
  }

Why element with index 2 is empty?

1 Answer 1

1

Because that's not an array, that's an object. Server-side you then convert it to an array. This conversion process is the problem. Send it as a dictionary ({1: "1", 2: "2", 3: "3", 4: "4", 5: "5"}) and PHP will know to convert it into a sparse array (which is a dictionary too).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.