A
A
artemk7n2017-07-11 12:30:16
PHP
artemk7n, 2017-07-11 12:30:16

How to write the first element in an array into a variable, then delete and take the next one?

Hello, I'm not strong in php, I've been suffering for 2 hours already, tell me please. There is such a task, you need to take the first value from an array, for example, 1000 values, write it to a variable and delete it from the array, and take the next one, and so on in a loop until the values ​​in the array become 0. how to do this?
i tried and here is my crooked code

<?php
$n = 3;
while($n >= 1)
{
    $array = array("per1", "per2", "per3");
    
    
    $elmas = $array[$n-1];
    
    echo $elmas;
  
      unset($array[$n-1]);
      

}

?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vyrkmod, 2017-07-11
@artemk7n

while (array_shift($array)) { ... }
Well, a link , of course.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question