Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6
Yes we can, copy & paste the following code on an empty PHP code. <?php /* Example: Use variables for array keys, the variable's value is used as the key. Notice that we use print_r to dump raw array into the output. */ $nama = "name"; $almt = "address"; $arr = array($nama=>"Your name", $almt=>"Your address"); echo "<p>We have the following code: <pre><code> \$nama = \"name\"; \$almt = \"address\"; \$arr = array(\$nama=>\"Your name\", \$almt=>\"Your address\"); </code></pre> </p>"; echo "<p>And so here's the array contents</p><strong>"; print_r($arr); echo "</strong>"; unset($arr); /* Example: Create and access array element by key using different type of quotes. Note that during array creation we use single quotes to assign the array keys. But when we use/access them we use double quotes. */ echo "<hr /><p>And we have this code: <pre><code> \$arr = array('name'=>'SoloLearner', 'address'=>'planet Earth'); echo \"&lt;p&gt;Hello, I am a \" . \$arr[\"name\"] . \" from \" . \$arr[\"address\"] . \"&lt;/p&gt;\"; </code></pre></p> <p>With the following output:<br />"; $arr = array('name'=>'SoloLearner', 'address'=>'planet Earth'); echo "<p><strong>Hello, I am a " . $arr["name"] . " from " . $arr["address"] . "</strong></p>"; ?>
17th Jan 2018, 11:10 AM
Ipang