function compac(array $data)
{
return array_filter($data, function($el) {
return !empty($el);
});
}
function test(array $in, array $up) {
if ( compac($in) == $up ) {
echo 'test complete!';
} else {
echo 'test not complete!';
}
}
test( [1,2,3,null], [1,2,3] );
<ul>
@foreach($items as $item)
<li>
<a href="{{ $item->url }}">{{ $item->title }}</a>
@if ($item->children)
<ul>
@foreach($item->children as $item_c)
<li><a href="{{ $item_c->url }}">{{ $item_c->title }}</a></li>
@endforeach
</ul>
@endif;
</li>
@endforeach
</ul>
$('table').wrap('<div class="table-wrap"></div>');
<button onclick="ajax()">ajax</button>
<script>
function ajax() {
var request = new XMLHttpRequest();
request.open('GET', 'ajax.php', true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
var data = JSON.parse(request.responseText);
alert(data);
} else {
}
};
request.onerror = function() {
};
request.send();
}
</script>
<?php
$res = 'текст из';
<?php
header('Content-Type: application/json');
include_once 'connect.php';
$data = array(
'html' => '<div class="new">'.$res.'</div>'
);
echo json_encode($data);