I have one constant file which contains all the status details ,i want to fetch the values from the constant file and store it inside an array in the form of indexed array, can you give me some idea how to do this one..
BooksConstants.php
class BooksConstants{
const PAID = 'settled';
const BOOK_FAILED_STATUSES = [
self::cancelled_by_customer,
self::FAILED,
self::FAILED_BY_GATEWAY,
self::INVALID_OTP
];
const BOOK_SUCCESS_STATUSES = [
self::PAID,
self::SUCCESS,
self::ON_THE_WAY,
self::PROGRESS
];
}
Controller.php
$array=[];
array_push($array,BooksConstants::BOOK_SUCCESS_STATUSES);
array_push($array,BooksConstants::BOOK_FAILED_STATUSES);
it's storing 0th index with all data for BOOK_SUCCESS_STATUES array and 1st index is storing for BOOK_FAILED_STATUES but my requirement is
$array=['failed','settled','failed by gateway'....);
CodePudding user response:
Using array_push you will actually push an array to the 0th-index and after that push another array to the 1st-index.
As stated in the comment, array_merge() can be used here instead, as it will just place the content of the arrays besides each other in the returned array.
$array = array_merge(BooksConstants::BOOK_SUCCESS_STATUSES, BooksConstants::BOOK_FAILED_STATUSES);