F
F
felony13twelve2020-05-10 22:41:45
PHP
felony13twelve, 2020-05-10 22:41:45

How to use a for loop inside an array?

Can you please tell me how to use for inside an array?

$arr = array(
'test' => array(
 for($i=0;$i<= 3;$i++) {
   $i => array(
      'he" => "hej"
    )
}
)
);


How right? :xD

Answer the question

In order to leave comments, you need to log in

1 answer(s)
4
4sadly, 2020-05-10
@felony13twelve

No, but here's an alternative: (in newer versions, instead of the "array" function, you can write "[]" )

$arr = ['test'];
$arr['test'] = [];
for($i=0;$i<= 3;$i++) {
$arr['test'][$i] = ['he'=>'hej'];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question