במדריך זה נלמד איך להציג מבנה מערך וערכים ב-PHP.
פונקציות בשימוש:
()print_r
()var_dump
ניתן להשתמש בפונקציה ()print_r או ()var_dump כדי לראות או לבדוק את המבנה והערכים של מערך בפורמט קריא אנושי על המסך.
()var_dump תספק מידע נוסף מעבר למה ש- ()print_r מספקת.
בפניכם דוגמא על אופן הביצוע:
שימוש ב-()print_r
<?php
$cities = array("Jerusalem", "Paris", "New York", "Amsterdam");
print_r($cities);
?>
פלט
Array ( [0] => Jerusalem [1] => Paris [2] => New York [3] => Amsterdam )
שימוש ב-()var_dump
<?php
$cities = array("Jerusalem", "Paris", "New York", "Amsterdam");
var_dump($cities);
?>
פלט
C:\wamp64\www\www\testcode\testcode.php:9: array (size=4) 0 => string 'Jerusalem' (length=9) 1 => string 'Paris' (length=5) 2 => string 'New York' (length=8) 3 => string 'Amsterdam' (length=9)