Creating An Array With Keys And Values

Hello!

In the last tutorial where I showed you how to create an arrays (view here), but in this tutorial I’m going to show how to add values to array keys.

There are many ways to do it. First I’m going to show to how to do it manually. It looks like this.

$arr = array(“key”=>”value”, “key2″=>”value2″);

It’s really good way to hold data in an array. I’m going to use myself in an example:

$arr = array(“name”=>”Jaan”, “weight”=>”83kg”, “height”=>”183cm”);

Second way to add values to your array is using array_merge() function which will merge 2 arrays. It goes like this:


Continue reading

Creating An Array

Hello!

Today I’m going to show you how to create arrays. It’s really simple and you can create them in 3 ways.

Using array function:

Easiest way to create an array is using array() function. It goes like this:

array([item], [item]…);

So if you use it in PHP it looks like this:

$arr = array(“dog”, “cat”, “pig”, “donkey”);

Using loop:


You can create arrays with loops. It works with all loops like while, do, for and foreach. I’m going to use for in this example:

Continue reading