Howdy, Stranger!

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

Categories

Adding elements to an empty array in PHP?

Damian99Damian99 USAPosts: 116Member

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

Tagged:

Comments

  • DavidMDavidM USAPosts: 342Member

    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.