PHP Embedding Numbers And Strings Into Other Strings – String Function

<?php
$arr = array(1 => "abc","abc" => 123.5,array(1,2,3));
$key = "abc"; echo "First value = $arr[1]\n";
echo "Second value = $arr[abc]\n";
echo "Third value = $arr[2]\n";
echo "Third value = $arr[2][2]\n"; echo "Second value = ${arr['abc']}\n";
echo "Second value = ${arr["abc"]}\n";
echo "Second value = ${arr[$key]}\n";
?> <?php
$arr = array(
    "abc" => "abc",
    "def" => 123.5,
    "ghi" => array(1,2,3)
);
$key = "abc";
$obj = (object) $arr; echo "First value = $obj->abc\n";
echo "Second value = $obj->def\n";
echo "Third value = $obj->ghi\n";
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.