/**
*
* Input array consists of elements as in example
* <code>
* Array
* (
* [0] => Array
* (
* [name] => Холопова Анастасия
* [num_meet1] => 4
* )
*
* [1] => Array
* (
* [name] => Погарченкова Мария
* [num_meet1] => 2
* )
*
* [2] => Array
* (
* [name] => Индутова Валерия
* [num_meet1] => 1
* )
*
* [3] => Array
* (
* [name] => Валерьянова Саша
* [num_meet2] => 1
* )
*
* [4] => Array
* (
* [name] => Валерьянова Саша
* [num_meet3] => 1
* )
*
* [5] => Array
* (
* [name] => Холопова Анастасия
* [num_meet4] => 1
* )
*
* )
* </code>
*
* @param array $array
*
* @return array
*/
function alterArray(array $array){
$newArray = [];
foreach($array as $subarray)
{
if(isset($subarray['name']))
{
$lastElementOfArray = array_slice($subarray, 1, 1);
reset($lastElementOfArray);
$newArray[ $subarray['name'] ][ key($lastElementOfArray) ] = current($lastElementOfArray);
}
}
return $newArray;
}
function getDatesForThisAndNextWeek()
{
$days = ['Monday' => 1, 'Tuesday' => 2, 'Wednesday' => 3, 'Thursday' => 4, 'Friday' => 5, 'Saturday' => 6, 'Sunday' => 7];
$i = 1;
foreach($days as $k => $v)
{
$today = new \DateTime();
$today->setISODate((int)$today->format('o'), (int)$today->format('W'), $days[ ucfirst($k) ]);
$daysArray[ $i ] = $today->format('Y-m-d');
$todayPlusWeek = $today->modify('+1 week');
$daysArray[ $i + 7 ] = $todayPlusWeek->format('Y-m-d');
$i++;
}
ksort($daysArray);
return $daysArray;
}
var_dump(getDatesForThisAndNextWeek());
И в контроллере пустую переменную не передать - ругается на invalid foreach.
Как тогда?
if(null === $myVar){
$myVar = [];
}
<?php
$subject = "abcdef";
$pattern = '/^def/';
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3);
print_r($matches);
?>
$('body').html( result );
<script>
window.location = "http://mysite.com/newlocation.htm"
<script>