1

I would like to access to the data inside an array of array that I'm sending with ajax to a .php page.

Creating the array of arrays in the function before sending

var xi = new Array(maxests);
$(".mtable").find(".allownumericwithdecimal").each(function(){
var nth = ((i) % maxests) + 3
var alt = $(this).parent().parent().find("td:first").html()
var est = $('.mtable').find("thead tr:first td:nth-child("+nth+")").html()
var pay = $(this).val()

xi[i] = new Array(alt,est,pay);
    i++;
})

Output on php:

Array(
[data] => Array
    (
      [name] => 
      [description] => 
      [project] => 1
      [ae] => [["Alternativa 1","Estado N. 1","1"],["Alternativa 1","Estado N. 2","23"],["Alternativa 2","Estado N. 1","33"],["Alternativa 2","Estado N. 2","43"]]
    ))

I would like to access the data inside ae.

echo $_POST['data']['ae'][0][0];

I'm trying this one, but not luck. How can I get the value of each one?

0

2 Answers 2

5

If that's a var_dump($_POST) or print_r($_POST), then this

[ae] => [["Alternativa 1","Estado N. 1","1"],["Alternativa 1","Estado N. 2","23"],["Alternativa 2","Estado N. 1","33"],["Alternativa 2","Estado N. 2","43"]]

is a string

$ae=json_decode($_POST['data']['ae']);

echo $ae[0][0]; // what you thought $_POST['data']['ae'][0][0]; would do

foreach ($ae as $a){
    print_r($a);
}

https://www.php.net/json_decode

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

1 Comment

@Maky-chan sorry - typo
0

Your array appears to be in an array

  $ae = $_POST[0]['data']['ae'];
  print_r($ae);

Should give you the breakdown of $ae. So in your example the first element of the first array would be

  echo $_POST[0]['data']['ae'][0][0];

output:

  Alternativa 1

I hope this helps.

1 Comment

Your "solution" is exactly what was reported in the question as not working. OP thought that it was an array.

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.