I'm creating a PHP script but I'm a beginner and I'm having a little trouble. I would like to delete these arrays which are added automatically and which come from nowhere and then merge those which have content. I have tried everything especially "array_filter" which does not change the problem of removing empty arrays. Someone can help me ?
Here is my script:
foreach ($items as $it) {
$title = array_key_exists(2, $it) ? $it[2] : null;
$description = array_key_exists(3, $it) ? $it[3] : null;
// Multiple images in each key
$img = array_key_exists(4, $it) ? $it[4] : null;
$secimg = explode(';', $img);
$cat = array_key_exists(5, $it) ? $it[5] : null;
$price = array_key_exists(8, $it) ? $it[8] : null;
$stock = array_key_exists(6, $it) ? $it[6] : null;
array_unshift($secimg, $title, $description, $cat, $price, $stock);
array_filter($secimg);
if(!empty($secimg) && !NULL){
echo '<pre>';
print_r($secimg);
echo '</pre>';
}
Here is the var dump of my script:
Array
(
[0] => Coin daté n°327 neufs
[1] => Value
[2] => Coins datés
[3] => 58.0
[4] =>
[5] => e8d753_2e4cea0057b848b8b6ef6e443fcac19b~mv2.jpg
[6] => e8d753_8a7af381ec334aa49f19424132e0461e~mv2.jpg
)
Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
)
Array
(
[0] => Coin daté n°327 neufs
[1] => Value
[2] => Coins datés
[3] => 58.0
[4] =>
[5] => e8d753_2e4cea0057b848b8b6ef6e443fcac19b~mv2.jpg
[6] => e8d753_8a7af381ec334aa49f19424132e0461e~mv2.jpg
)
Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
)
Thank you !