Explanation of a php array and how to access the x position of the PHP array [closed]

0

I need a brief explanation about arrays in php I've been researching and to no avail.

For example if you try something like this where I'm looking for the timetables on the database, the echo does not work, I'm also working with ajax

<?php
    $count=0;
    while ($dados = mysql_fetch_array($result){
        $count=$count+1;
         $hora= $dados['horarioHora'];

        }
    }echo $hora[$count];
?>
    
asked by anonymous 13.05.2016 / 23:25

1 answer

1

Good here in case you have a variable time and not an array.

To be array should have done

<?php
    $count=0;
    while ($arrayDisp = mysql_fetch_array($result){
        $count=$count+1;
        $hora[] = $arrayDisp['horarioHora'];

    }
    echo $hora[$count -1];
?>

You were also throwing the result of your select into an array and reading something else. This way it will get the last position of the array now if it is the most recent time depends on your query more specifically the order by. I did not test, but I think this should solve, I hope I have helped.

    
13.05.2016 / 23:43