$handle = fopen('php://memory', 'r+');
$data = [
['id' => 1,'name' => 'test1'],
['id' => 2,'name' => 'test3'],
['id' => 3,'name' => 'test3'],
]; // тут данные с БД в в виде массива
$first = true;
foreach($data as $row) {
if($first) {
fputcsv($handle, array_keys($row));
$first = false;
}
fputcsv($handle, $row);
}
rewind($handle);
// mb_convert_encoding($csv, 'iso-8859-2', 'utf-8')
$content = stream_get_contents($handle);
// тут пишем в файл или выдаем на экран
fclose($handle);
$array1 = [
[
"link"=> "http://site.com/34",
"movie_file" => "set33.zip"
], [
"link"=> "http://site.com/12",
"movie_file" => "set33.zip"
]
];
$array2 = [
[
"link"=> "http://site.com/test",
"movie_file" => "set33.zip"
], [
"link"=> "http://site.com/12",
"movie_file" => "set33.zip"
]
];
function keyCompareFunc($key1, $key2)
{
$val1 = $key1['link'];
$val2 = $key2['link'];
return strcasecmp($val1,$val2);
}
$list= array_udiff($array1,$array2,'keyCompareFunc');
var_dump($list);
SELECT *
FROM message
WHERE
(user_one='11' AND user_two='16')
OR
(user_one='11' AND user_two='13')
set @user_id=11;
SELECT id, last_message_id, update_at, user_one, user_two FROM message_dialog
where user_one =@user_id or user_two=@user_id;
set @dialog_id=5;
select id, dialog_id, user_id, message, created_at, etc from dialog_message where dialog_id=@dialog_id order by id desc
fucnction lockOrderUrl($url,$lockUrl = '#'){
$hour = date('H');
$lockLink = ($hour >=21 || $hour <=10 );
return $lockLink ? $lockUrl : $url;
}
<a href="<?=lockOrderUrl('Тут путь к заказу', 'линк куда нужно перекидывать можно зашить в функцию если он не меняется'); ?>
Class ArrayHelper {
public static function getValue($array, $key, $default = null)
{
if ($key instanceof \Closure) {
return $key($array, $default);
}
if (is_array($key)) {
$lastKey = array_pop($key);
foreach ($key as $keyPart) {
$array = static::getValue($array, $keyPart);
}
$key = $lastKey;
}
if (is_array($array) && array_key_exists($key, $array)) {
return $array[$key];
}
if (($pos = strrpos($key, '.')) !== false) {
$array = static::getValue($array, substr($key, 0, $pos), $default);
$key = substr($key, $pos + 1);
}
if (is_object($array)) {
// this is expected to fail if the property does not exist, or __get() is not implemented
// it is not reliably possible to check whether a property is accessable beforehand
return $array->$key;
} elseif (is_array($array)) {
return array_key_exists($key, $array) ? $array[$key] : $default;
} else {
return $default;
}
}
}