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

Asked

Viewed 28 times

0

I need a brief explanation about arrays in php I’ve been searching and without success.

For example if I try something like where I’m getting the based schedules 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];
?>
  • 2

    I could not understand what echo should return?

  • The last hour that this in the database I already edited my code I hope that now is easier

1 answer

1


well there 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 playing your select result for an array and reading something else. This way ai will get the last position of the array now if it is the most recent time depends on your query more specifically of order by. I didn’t test it, but I think it should fix it, I hope it helped.

  • It worked that was the problem the []

Browser other questions tagged

You are not signed in. Login or sign up in order to post.