Better way to build an array?

Im using the following array, but wondering if theres a better way to load this data from an external file? or is this the best way?

	$people = array(

"0" => array(
	"name" => 'Peter',
	"job" => "Builder",
	"location" => "Ca"
),

"1" => array(
	"name" => 'Bob',
	"job" => "Designer",
	"location" => "Ca"
),
"2" => array(
	"name" => 'Tony',
	"job" => "Manager",
	"location" => "Fl"
),	

);

Well, arrays are handy, but, for names, jobs and locations, why not use a database?
Then, you can run queries to locate everyone from Ca vs Fl, etc. Or all Builders or everyone named Tony.

Arrays are very useful for what they are used for. But, for data arrays, especially large amounts of data,
you would want to use an array.

Thats just example data, the actual use makes more sense to have it like that rather than a database

Well, your example is just fine. The indexes would be used like this:

foreach($people as $key=>$person) {
    some process for one persons...
    echo $person["name"] . "<br>";
}

The $person is actually a second level array. Or you could access it as echo $people[1][“name”]; which also works. Either way, this is not used for large numbers of data…

maka CSV (comma separated value) text file.

Load it with PHP: file - Manual and convert each line of the file to an array with PHP: explode - Manual

Or use a dedicated class for working with CSV files.

It’s not working for me for some reason

What isn’t? You hijacking this post?

Sponsor our Newsletter | Privacy Policy | Terms of Service