Answer the question
In order to leave comments, you need to log in
How to nest an array in a cell whose key is auto-incrementing( $name[]) (PHP)?
Good afternoon.
Question:
How about an array whose elements are created in the form:
$users[] = $user['info'];
Add some other value to the created cell?
To make it work for example - so?
a[1][info] = 'test'
a[1][status] = 'online'
There is a loop that forms an array, it looks like this:
for simplicity, the example is made up
Structure:
$users[0..N][sex]
$users[0..N][user_info]
foreach ($users as $key => $value) {
switch ($value['sex']) {
case 1:
$men[] = $value['user_info'];
//как можно к массиву $men добавить еще 1 массив?
//$men[] = array('status' => 'online'); такая строка, естественно создаст новый элемент массива.
break;
case 0:
$women[] = $value['user_info'];
break;
default:
break;
}
}
Answer the question
In order to leave comments, you need to log in
$men[] = array (
'user_ifo' => $value['user_info'],
'status' => 'online'
);
$men[count($men) - 1]['status'] = 'online';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question