Adding elements to an empty array in PHP?

Can someone please let me know how to add elements to an empty PHP array?

Comments

  • There are 2 ways.

    <?php
    $marks = array();
    $marks[] = 45;
    $marks[] = 85;
    ?>
    

    or

    <?php
    $marks = array();
    array_push($marks, 45);
    array_push($marks, 85);
    
    // Or 
    $marks = array();
    array_push($marks, 45, 85);
    ?>
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion