mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-27 00:14:05 +00:00
28 lines
663 B
PHP
28 lines
663 B
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Segments\Services;
|
|
|
|
class RemoveItemFromConstantValueArray
|
|
{
|
|
|
|
/**
|
|
* @param array|string|null $array
|
|
* @param $item
|
|
* @return array
|
|
*/
|
|
public function execute($array, $item): array {
|
|
// PHP 8.3: Ensure $array is always an array, even if JSON cast fails
|
|
// Handle cases where value might be empty string, null, or invalid JSON
|
|
if (!is_array($array)) {
|
|
$array = [];
|
|
}
|
|
|
|
foreach($array as $key => $value){
|
|
if($array[$key] == $item){
|
|
unset($array[$key]);
|
|
}
|
|
}
|
|
return array_values($array);
|
|
}
|
|
|
|
} |