bucle de matriz PHP
for ($i = 0; $i < count($array); $i++) {
echo $array[$i]['filename'];
echo $array[$i]['filepath'];
}
Clever Cardinal
for ($i = 0; $i < count($array); $i++) {
echo $array[$i]['filename'];
echo $array[$i]['filepath'];
}
$arr = ['Item 1', 'Item 2', 'Item 3'];
foreach ($arr as $item) {
var_dump($item);
}
foreach($array as $item) {
echo $item['filename'];
echo $item['filepath'];
// To know what's in $item
echo '<pre>'; var_dump($item);
}
foreach ($name as $key => $value) {
echo ("Position {$key} enthält {$value}. ");
}
$CodeWallTutorialArray = ["Eggs", "Bacon", "HashBrowns", "Beans", "Bread", "RedSauce"];
for ($i = 0; $i < count($CodeWallTutorialArray); $i++) {
echo $CodeWallTutorialArray[$i] ."<br />";
}Copy
/**
* Get the author of the post.
*/
public function user()
{
return $this->belongsTo(User::class)->withDefault([
'name' => 'Guest Author',
]);
}
/**
* Get the author of the post.
*/
public function user()
{
return $this->belongsTo(User::class)->withDefault(function ($user, $post) {
$user->name = 'Guest Author';
});
}