I am creating APP for Shopify and I need the last fulfillment id of an order.
This is my code
if($value['fulfillment_status'] == 'fulfilled') {
foreach($value['fulfillments'] as $id) {
echo $id['id'].'<br>';
}
}
The output is
3549057974422
3555100033174
3557460050070
3560109277334
3560268103830
3560845475990
3561173024918
I only want to save or get the last fulfillment id value which is
3561173024918
How to do this ?
Regards
4
Answers
you can use this PHP function :
end($value['fulfillment_status'])
which will give you the last element in the array, your code will be like this :PHP has a built-in function for that
https://www.php.net/manual/en/function.array-key-last.php
The end function returns the last value of an array and sets the pointer to the last value.
Based on your output,
end($value['fulfillments'])
would return3561173024918
as required.You can use end().