Invoeging van assosiatiewe skikking elemente in PHP
Maar invoeging van assosiatiewe skikking elemente sal nie net so werk nie:
<?php
$arr = ['a'=>1, 'b'=>2, 'c'=>3];
echo "xxx $arr['a'] yyy"; // werk nie
?>
Vir die invoeging van sulke elemente moet dit in krulhakies toegedraai word:
<?php
$arr = ['a'=>1, 'b'=>2, 'c'=>3];
echo "xxx {$arr['a']} yyy";
?>
Of jy kan die enkelkwotasies van die sleutel verwyder tydens invoeging:
<?php
$arr = ['a'=>1, 'b'=2, 'c'=3];
echo "xxx $arr[a] yyy";
?>
Soms is dit sinvol om eenvoudig 'n skikking element in 'n veranderlike op te slaan, om dit dan sonder probleme in 'n string in te voeg:
<?php
$arr = ['a', 'b', 'c'];
$elem = $arr['a'];
echo "xxx $elem yyy";
?>
Vereenvoudig die volgende kode:
<?php
$arr = ['a' => 1, 'b' => 2, 'c' => 3];
echo 'text ' . $arr['a'] . ' text ' . $arr['b'] . ' text';
?>