How to find the last nested element of a two-dimensional array?

<?php $arr = array( "foo" => "bar", "bar" => "foo", "name" => array(1,2,333), // получить 333 100 => -100 ); 

Closed due to the fact that the essence of the issue is not clear to the participants of Regent , Streletz , Bald , user194374, aleksandr barakin 18 Jul '16 at 7:17 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    Why 1? Judging by the question 333 is necessary. - pavel
  • Well, where does the last element of the array come from ?! - Dmitriy Simushev 7:55 pm
  • First, decide on what you need, and then ask questions. Editing a question every five seconds does not do you the honor! - Dmitriy Simushev
  • @DmitriySimushev is the final version - jo_ho13121212
  • 2
    @ jo_ho13121212, for the third time you change the conditions of the question, there is a risk that you will just be warned and then no one will see the question. - cheops

1 answer 1

You can do the following:

 <?php $arr = array( "foo" => "bar", "bar" => "foo", "name" => array(1,2,333), 100 => -100 ); foreach($arr as $el) { if(is_array($el)) { echo end($el); break; } } 
  • one
    I think it is worth waiting for the final formalization of the task. And now this is a game of “guessing game” (or telepathy) - Dmitriy Simushev
  • @DmitriySimushev yup - cheops pm
  • described as accurately as possible - jo_ho13121212
  • @ jo_ho13121212, well, you were given a clear answer to your "as accurately as possible". If it does not suit you, then the problem is clearly not in the answer ;-) - Dmitriy Simushev