I have an array in my php code
$list = array(
'RETAIL' => 'SUPERMARKET'
'RETAIL' => 'BAR'
'RETAIL' => 'DEP. MARKET'
'BUSINESS' => 'HOTEL'
'BUSINESS' => 'PUB'
'OTHER' => 'GROCERY'
'OTHER' => 'BUTCHERY'
// I have 20+ items
);
foreach( $list as $type => $name ){
var_dump($type,$name);
}
//var_dump() output
// RETAIL SUPERMARKET
// BUSINESS HOTEL
// OTHER BUTCHERY
I’m facing the problem that when I try to loop the array only three values will be returned and the rest are ignored. How I can fix this?
I’m trying to loop the array to save the data into a custom wordpress database. With the same way I’ve successfully looped another array inserted the keys and values into the db.
3
Answers
I think a better structure for your array would something like this
And you could loop over like so
Just an example
As a general way of handling instances where you have more than one element to each piece of data (even when it’s not in a tree structure like this may be), you should structure each item in the list as either an array or object, eg:
or
Maybe I show heavily but as you only have two data for each entity, why your table is not built like this at the base…?
You do have keys that uniquely identify entities.