How to Convert an Object into Array in magento 2Convert mysql query into magento model formatMagento2: Convert DataObject/Array into magento2 Collection?Magento 2 convert object to arrayMagento 2: How to convert product array into collection?Magento 1 - Convert Object into an array valueMagento 2 CMS 404 errorHow to convert this object data into array?Trying to access the admin backend in Magento2 throws a 404 not foundConvert(re-write) array_filter code into foreach looparray convert into Magento 2 collection

How is linear momentum conserved in circular motion?

...and then she held the gun

Are there examples of rowers who also fought?

Justifying Affordable Bespoke Spaceships

Using roof rails to set up hammock

Explicit song lyrics checker

Build a scale without computer

Is using Legacy mode is a bad thing to do?

How to recover a single blank shot from a film camera

What kind of chart is this?

How can I ping multiple IP addresses at the same time?

Kelvin type connection

Is there a polite way to ask about one's ethnicity?

Can a character with the Polearm Master feat make an opportunity attack against an invisible creature that enters their reach?

How can I maintain game balance while allowing my player to craft genuinely useful items?

How valuable is a categorical feature that has a predominant category over all other ones?

How to ask if I can mow my neighbor's lawn

Print the new site header

What is the context for Napoleon's quote "[the Austrians] did not know the value of five minutes"?

How to make all magic-casting innate, but still rare?

How did the European Union reach the figure of 3% as a maximum allowed deficit?

How to write a nice frame challenge?

Digital signature that is only verifiable by one specific person

Got a new frameset, don't know why I need this split ring collar?



How to Convert an Object into Array in magento 2


Convert mysql query into magento model formatMagento2: Convert DataObject/Array into magento2 Collection?Magento 2 convert object to arrayMagento 2: How to convert product array into collection?Magento 1 - Convert Object into an array valueMagento 2 CMS 404 errorHow to convert this object data into array?Trying to access the admin backend in Magento2 throws a 404 not foundConvert(re-write) array_filter code into foreach looparray convert into Magento 2 collection






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








4















i Need All cms pages in an array I got All in an object but the format i got is not that I expected



$cms = $this->collectionFactory->create()->toOptionIdArray();
echo "<pre>";
print_r($cms->toArray());
exit();


these lines gave me result as



Array
(
[0] => Array
(
[value] => no-route
[label] => 404 Not Found
)

[1] => Array
(
[value] => home
[label] => Home Page
)

[2] => Array
(
[value] => enable-cookies
[label] => Enable Cookies
)

[3] => Array
(
[value] => privacy-policy-cookie-restriction-mode
[label] => Privacy Policy
)

)


but i need this something like



Array
(
[
"value" => 'no-route',
"label" => '404 Not Found'
],
[
"value" => 'home',
"label" => 'Home Page'
],
[
"value" => 'enable-cookies',
"label" => 'Enable Cookies'
],
[
"value" => 'privacy-policy-cookie-restriction-mode',
"label" => 'Privacy Policy'
],

]


i want to add CMS pages in a drop down



$options = [
[
'label' => __('Catagories'),
'value' => [
[
'label' => __('Anchor Catagories'),
'value' => self::CATAGORIES_ANCHORED
],
[
'label' => __('Non-Anchor Catagories'),
'value' => self::NON_CATAGORIES_ANCHORED
]
]
],
[
'label' => __('All Products'),
'value' => [
[
'label' => __('All Product Types'),
'value' => self::PRODUCT_ALL
],
[
'label' => __('Simple Product'),
'value' => self::PRODUCT_SIMPLE
],
[
'label' => __('Virtual Products'),
'value' => self::PRODUCT_VIRUAL
],
[
'label' => __('Downloadable Products'),
'value' => self::PRODUCT_DOWNLOADABLE
],
[
'label' => __('Configureable Products'),
'value' => self::PRODUCT_CONFIGUREABLE
],
[
'label' => __('Grouped Products'),
'value' => self::PRODUCT_GROUPED
],
[
'label' => __('Bundle Products'),
'value' => self::PRODUCT_BUNDLED
]
]
],
[
'label' => __('CMS pages'),
'value' => [


]
]
];


in the CMS pages options










share|improve this question
























  • I think both are same. I dont get any difference between what you get and what you want ..

    – Yash Shah
    Jun 10 at 6:12











  • @YashShah check updated question

    – Waqar Ali
    Jun 10 at 6:19











  • You can code like this. $options[2]['value'] = $cms->toArray();

    – Yash Shah
    Jun 10 at 6:25











  • on toArray() getting error Fatal error: Uncaught Error: Call to a member function toArray() on array

    – Waqar Ali
    Jun 10 at 6:29






  • 1





    In that case, $options[2]['value'] = $cms; should work.

    – Yash Shah
    Jun 10 at 6:39

















4















i Need All cms pages in an array I got All in an object but the format i got is not that I expected



$cms = $this->collectionFactory->create()->toOptionIdArray();
echo "<pre>";
print_r($cms->toArray());
exit();


these lines gave me result as



Array
(
[0] => Array
(
[value] => no-route
[label] => 404 Not Found
)

[1] => Array
(
[value] => home
[label] => Home Page
)

[2] => Array
(
[value] => enable-cookies
[label] => Enable Cookies
)

[3] => Array
(
[value] => privacy-policy-cookie-restriction-mode
[label] => Privacy Policy
)

)


but i need this something like



Array
(
[
"value" => 'no-route',
"label" => '404 Not Found'
],
[
"value" => 'home',
"label" => 'Home Page'
],
[
"value" => 'enable-cookies',
"label" => 'Enable Cookies'
],
[
"value" => 'privacy-policy-cookie-restriction-mode',
"label" => 'Privacy Policy'
],

]


i want to add CMS pages in a drop down



$options = [
[
'label' => __('Catagories'),
'value' => [
[
'label' => __('Anchor Catagories'),
'value' => self::CATAGORIES_ANCHORED
],
[
'label' => __('Non-Anchor Catagories'),
'value' => self::NON_CATAGORIES_ANCHORED
]
]
],
[
'label' => __('All Products'),
'value' => [
[
'label' => __('All Product Types'),
'value' => self::PRODUCT_ALL
],
[
'label' => __('Simple Product'),
'value' => self::PRODUCT_SIMPLE
],
[
'label' => __('Virtual Products'),
'value' => self::PRODUCT_VIRUAL
],
[
'label' => __('Downloadable Products'),
'value' => self::PRODUCT_DOWNLOADABLE
],
[
'label' => __('Configureable Products'),
'value' => self::PRODUCT_CONFIGUREABLE
],
[
'label' => __('Grouped Products'),
'value' => self::PRODUCT_GROUPED
],
[
'label' => __('Bundle Products'),
'value' => self::PRODUCT_BUNDLED
]
]
],
[
'label' => __('CMS pages'),
'value' => [


]
]
];


in the CMS pages options










share|improve this question
























  • I think both are same. I dont get any difference between what you get and what you want ..

    – Yash Shah
    Jun 10 at 6:12











  • @YashShah check updated question

    – Waqar Ali
    Jun 10 at 6:19











  • You can code like this. $options[2]['value'] = $cms->toArray();

    – Yash Shah
    Jun 10 at 6:25











  • on toArray() getting error Fatal error: Uncaught Error: Call to a member function toArray() on array

    – Waqar Ali
    Jun 10 at 6:29






  • 1





    In that case, $options[2]['value'] = $cms; should work.

    – Yash Shah
    Jun 10 at 6:39













4












4








4








i Need All cms pages in an array I got All in an object but the format i got is not that I expected



$cms = $this->collectionFactory->create()->toOptionIdArray();
echo "<pre>";
print_r($cms->toArray());
exit();


these lines gave me result as



Array
(
[0] => Array
(
[value] => no-route
[label] => 404 Not Found
)

[1] => Array
(
[value] => home
[label] => Home Page
)

[2] => Array
(
[value] => enable-cookies
[label] => Enable Cookies
)

[3] => Array
(
[value] => privacy-policy-cookie-restriction-mode
[label] => Privacy Policy
)

)


but i need this something like



Array
(
[
"value" => 'no-route',
"label" => '404 Not Found'
],
[
"value" => 'home',
"label" => 'Home Page'
],
[
"value" => 'enable-cookies',
"label" => 'Enable Cookies'
],
[
"value" => 'privacy-policy-cookie-restriction-mode',
"label" => 'Privacy Policy'
],

]


i want to add CMS pages in a drop down



$options = [
[
'label' => __('Catagories'),
'value' => [
[
'label' => __('Anchor Catagories'),
'value' => self::CATAGORIES_ANCHORED
],
[
'label' => __('Non-Anchor Catagories'),
'value' => self::NON_CATAGORIES_ANCHORED
]
]
],
[
'label' => __('All Products'),
'value' => [
[
'label' => __('All Product Types'),
'value' => self::PRODUCT_ALL
],
[
'label' => __('Simple Product'),
'value' => self::PRODUCT_SIMPLE
],
[
'label' => __('Virtual Products'),
'value' => self::PRODUCT_VIRUAL
],
[
'label' => __('Downloadable Products'),
'value' => self::PRODUCT_DOWNLOADABLE
],
[
'label' => __('Configureable Products'),
'value' => self::PRODUCT_CONFIGUREABLE
],
[
'label' => __('Grouped Products'),
'value' => self::PRODUCT_GROUPED
],
[
'label' => __('Bundle Products'),
'value' => self::PRODUCT_BUNDLED
]
]
],
[
'label' => __('CMS pages'),
'value' => [


]
]
];


in the CMS pages options










share|improve this question
















i Need All cms pages in an array I got All in an object but the format i got is not that I expected



$cms = $this->collectionFactory->create()->toOptionIdArray();
echo "<pre>";
print_r($cms->toArray());
exit();


these lines gave me result as



Array
(
[0] => Array
(
[value] => no-route
[label] => 404 Not Found
)

[1] => Array
(
[value] => home
[label] => Home Page
)

[2] => Array
(
[value] => enable-cookies
[label] => Enable Cookies
)

[3] => Array
(
[value] => privacy-policy-cookie-restriction-mode
[label] => Privacy Policy
)

)


but i need this something like



Array
(
[
"value" => 'no-route',
"label" => '404 Not Found'
],
[
"value" => 'home',
"label" => 'Home Page'
],
[
"value" => 'enable-cookies',
"label" => 'Enable Cookies'
],
[
"value" => 'privacy-policy-cookie-restriction-mode',
"label" => 'Privacy Policy'
],

]


i want to add CMS pages in a drop down



$options = [
[
'label' => __('Catagories'),
'value' => [
[
'label' => __('Anchor Catagories'),
'value' => self::CATAGORIES_ANCHORED
],
[
'label' => __('Non-Anchor Catagories'),
'value' => self::NON_CATAGORIES_ANCHORED
]
]
],
[
'label' => __('All Products'),
'value' => [
[
'label' => __('All Product Types'),
'value' => self::PRODUCT_ALL
],
[
'label' => __('Simple Product'),
'value' => self::PRODUCT_SIMPLE
],
[
'label' => __('Virtual Products'),
'value' => self::PRODUCT_VIRUAL
],
[
'label' => __('Downloadable Products'),
'value' => self::PRODUCT_DOWNLOADABLE
],
[
'label' => __('Configureable Products'),
'value' => self::PRODUCT_CONFIGUREABLE
],
[
'label' => __('Grouped Products'),
'value' => self::PRODUCT_GROUPED
],
[
'label' => __('Bundle Products'),
'value' => self::PRODUCT_BUNDLED
]
]
],
[
'label' => __('CMS pages'),
'value' => [


]
]
];


in the CMS pages options







magento2 php






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









Aasim Goriya

3,19211141




3,19211141










asked Jun 10 at 5:57









Waqar AliWaqar Ali

11011




11011












  • I think both are same. I dont get any difference between what you get and what you want ..

    – Yash Shah
    Jun 10 at 6:12











  • @YashShah check updated question

    – Waqar Ali
    Jun 10 at 6:19











  • You can code like this. $options[2]['value'] = $cms->toArray();

    – Yash Shah
    Jun 10 at 6:25











  • on toArray() getting error Fatal error: Uncaught Error: Call to a member function toArray() on array

    – Waqar Ali
    Jun 10 at 6:29






  • 1





    In that case, $options[2]['value'] = $cms; should work.

    – Yash Shah
    Jun 10 at 6:39

















  • I think both are same. I dont get any difference between what you get and what you want ..

    – Yash Shah
    Jun 10 at 6:12











  • @YashShah check updated question

    – Waqar Ali
    Jun 10 at 6:19











  • You can code like this. $options[2]['value'] = $cms->toArray();

    – Yash Shah
    Jun 10 at 6:25











  • on toArray() getting error Fatal error: Uncaught Error: Call to a member function toArray() on array

    – Waqar Ali
    Jun 10 at 6:29






  • 1





    In that case, $options[2]['value'] = $cms; should work.

    – Yash Shah
    Jun 10 at 6:39
















I think both are same. I dont get any difference between what you get and what you want ..

– Yash Shah
Jun 10 at 6:12





I think both are same. I dont get any difference between what you get and what you want ..

– Yash Shah
Jun 10 at 6:12













@YashShah check updated question

– Waqar Ali
Jun 10 at 6:19





@YashShah check updated question

– Waqar Ali
Jun 10 at 6:19













You can code like this. $options[2]['value'] = $cms->toArray();

– Yash Shah
Jun 10 at 6:25





You can code like this. $options[2]['value'] = $cms->toArray();

– Yash Shah
Jun 10 at 6:25













on toArray() getting error Fatal error: Uncaught Error: Call to a member function toArray() on array

– Waqar Ali
Jun 10 at 6:29





on toArray() getting error Fatal error: Uncaught Error: Call to a member function toArray() on array

– Waqar Ali
Jun 10 at 6:29




1




1





In that case, $options[2]['value'] = $cms; should work.

– Yash Shah
Jun 10 at 6:39





In that case, $options[2]['value'] = $cms; should work.

– Yash Shah
Jun 10 at 6:39










2 Answers
2






active

oldest

votes


















4














Why not?



$cms = $this->collectionFactory->create()->toOptionArray();
$options = [
// your code
[
'label' => __('CMS pages'),
'value' => $cms
]
];





share|improve this answer























  • that worked for me thank you

    – Waqar Ali
    Jun 10 at 7:17


















3














Try Foreach loop will help.



Syntex :



$data = $cms->toArray();

foreach ($variable as $key => $value)





let me know if anything you need.



Thanks






share|improve this answer

























  • strill getting same result

    – Waqar Ali
    Jun 10 at 6:09











  • try once $collection->toArray();

    – Adarsh Shukla
    Jun 10 at 6:13











  • i tried this getting Fatal error: Uncaught Error: Call to a member function toArray() on array

    – Waqar Ali
    Jun 10 at 6:21











  • have you eddited question?

    – Adarsh Shukla
    Jun 10 at 6:22











  • yes i just added code where i want to add these options

    – Waqar Ali
    Jun 10 at 6:23











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f277760%2fhow-to-convert-an-object-into-array-in-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














Why not?



$cms = $this->collectionFactory->create()->toOptionArray();
$options = [
// your code
[
'label' => __('CMS pages'),
'value' => $cms
]
];





share|improve this answer























  • that worked for me thank you

    – Waqar Ali
    Jun 10 at 7:17















4














Why not?



$cms = $this->collectionFactory->create()->toOptionArray();
$options = [
// your code
[
'label' => __('CMS pages'),
'value' => $cms
]
];





share|improve this answer























  • that worked for me thank you

    – Waqar Ali
    Jun 10 at 7:17













4












4








4







Why not?



$cms = $this->collectionFactory->create()->toOptionArray();
$options = [
// your code
[
'label' => __('CMS pages'),
'value' => $cms
]
];





share|improve this answer













Why not?



$cms = $this->collectionFactory->create()->toOptionArray();
$options = [
// your code
[
'label' => __('CMS pages'),
'value' => $cms
]
];






share|improve this answer












share|improve this answer



share|improve this answer










answered Jun 10 at 7:11









tokeytokey

862




862












  • that worked for me thank you

    – Waqar Ali
    Jun 10 at 7:17

















  • that worked for me thank you

    – Waqar Ali
    Jun 10 at 7:17
















that worked for me thank you

– Waqar Ali
Jun 10 at 7:17





that worked for me thank you

– Waqar Ali
Jun 10 at 7:17













3














Try Foreach loop will help.



Syntex :



$data = $cms->toArray();

foreach ($variable as $key => $value)





let me know if anything you need.



Thanks






share|improve this answer

























  • strill getting same result

    – Waqar Ali
    Jun 10 at 6:09











  • try once $collection->toArray();

    – Adarsh Shukla
    Jun 10 at 6:13











  • i tried this getting Fatal error: Uncaught Error: Call to a member function toArray() on array

    – Waqar Ali
    Jun 10 at 6:21











  • have you eddited question?

    – Adarsh Shukla
    Jun 10 at 6:22











  • yes i just added code where i want to add these options

    – Waqar Ali
    Jun 10 at 6:23















3














Try Foreach loop will help.



Syntex :



$data = $cms->toArray();

foreach ($variable as $key => $value)





let me know if anything you need.



Thanks






share|improve this answer

























  • strill getting same result

    – Waqar Ali
    Jun 10 at 6:09











  • try once $collection->toArray();

    – Adarsh Shukla
    Jun 10 at 6:13











  • i tried this getting Fatal error: Uncaught Error: Call to a member function toArray() on array

    – Waqar Ali
    Jun 10 at 6:21











  • have you eddited question?

    – Adarsh Shukla
    Jun 10 at 6:22











  • yes i just added code where i want to add these options

    – Waqar Ali
    Jun 10 at 6:23













3












3








3







Try Foreach loop will help.



Syntex :



$data = $cms->toArray();

foreach ($variable as $key => $value)





let me know if anything you need.



Thanks






share|improve this answer















Try Foreach loop will help.



Syntex :



$data = $cms->toArray();

foreach ($variable as $key => $value)





let me know if anything you need.



Thanks







share|improve this answer














share|improve this answer



share|improve this answer








edited Jun 10 at 6:33









Rk Rathod

2,314315




2,314315










answered Jun 10 at 6:07









Adarsh ShuklaAdarsh Shukla

34714




34714












  • strill getting same result

    – Waqar Ali
    Jun 10 at 6:09











  • try once $collection->toArray();

    – Adarsh Shukla
    Jun 10 at 6:13











  • i tried this getting Fatal error: Uncaught Error: Call to a member function toArray() on array

    – Waqar Ali
    Jun 10 at 6:21











  • have you eddited question?

    – Adarsh Shukla
    Jun 10 at 6:22











  • yes i just added code where i want to add these options

    – Waqar Ali
    Jun 10 at 6:23

















  • strill getting same result

    – Waqar Ali
    Jun 10 at 6:09











  • try once $collection->toArray();

    – Adarsh Shukla
    Jun 10 at 6:13











  • i tried this getting Fatal error: Uncaught Error: Call to a member function toArray() on array

    – Waqar Ali
    Jun 10 at 6:21











  • have you eddited question?

    – Adarsh Shukla
    Jun 10 at 6:22











  • yes i just added code where i want to add these options

    – Waqar Ali
    Jun 10 at 6:23
















strill getting same result

– Waqar Ali
Jun 10 at 6:09





strill getting same result

– Waqar Ali
Jun 10 at 6:09













try once $collection->toArray();

– Adarsh Shukla
Jun 10 at 6:13





try once $collection->toArray();

– Adarsh Shukla
Jun 10 at 6:13













i tried this getting Fatal error: Uncaught Error: Call to a member function toArray() on array

– Waqar Ali
Jun 10 at 6:21





i tried this getting Fatal error: Uncaught Error: Call to a member function toArray() on array

– Waqar Ali
Jun 10 at 6:21













have you eddited question?

– Adarsh Shukla
Jun 10 at 6:22





have you eddited question?

– Adarsh Shukla
Jun 10 at 6:22













yes i just added code where i want to add these options

– Waqar Ali
Jun 10 at 6:23





yes i just added code where i want to add these options

– Waqar Ali
Jun 10 at 6:23

















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f277760%2fhow-to-convert-an-object-into-array-in-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?