Hello i have a table with many columns, each column has a row called phone_number now this row can either be null or filled with 1 or more phone numbers so its serialized the value. Now i want to fetch the phone numbers and this is the code i have until now
foreach ($myActions as $action) {
if ($action->phone_number) {
$phoneArray = unserialize($action->phone_number);
}
}
I want to add a default value like —- so when i make this code:
<td>
@foreach($phoneArray as $phone)
<p class="badge badge-info"> {{ $phone }} </p>
@endforeach
</td>
To show result:
1
*----*
2
3
4
*----*
2
Answers
You don’t need to create any default value.
You can use the PHP Null coalescing operator:
??
, which will output the second expression if$phone
is nullCheck when variable phone is not empty