I have the following array. I'm not even sure if that array is properly formatted. I am not even sure if my array is right.
I want to convert the following array to a serialized XML using PHP. I am using attr tag for the attributes.
Here is the array:
$data = Array(
'name' => 'account',
'attr' => Array(
'id' => 123456
),
'children' => Array(
Array(
'name' => 'name',
'attr' => Array(),
'children' => Array(
'BBC'
),
),
Array(
'name' => 'monitors',
'attr' => Array(),
'children' => Array(
Array(
'name' => 'monitor',
'attr' => Array(
'id' => 5235632
),
'children' => Array(
Array(
'name' => 'url',
'attr' => Array(),
'children' => Array(
'http://www.bbc.co.uk/'
)
)
)
),
Array(
'name' => 'monitor',
'attr' => Array(
'id' => 5235633
),
'children' => Array(
Array(
'name' => 'url',
'attr' => Array(),
'children' => Array(
'http://www.bbc.co.uk/news'
)
)
)
)
)
)
)
);
It is quite easy with a recursive function. Your basic array contains 3 elements, the name, the attribute list and the children. So your function has to create and append a node with the name, set all attributes and iterate the child data. If the child is an scalar it is a text node, for an array call the function itself.
function appendTo($parent, $data) {
$document = $parent->ownerDocument ?: $parent;
$node = $parent->appendChild($document->createElement($data['name']));
if (isset($data['attr']) && is_array($data['attr'])) {
foreach ($data['attr'] as $name => $value) {
$node->setAttribute($name, $value);
}
}
if (isset($data['children']) && is_array($data['children'])) {
foreach ($data['children'] as $name => $childData) {
if (is_scalar($childData)) {
$node->appendChild($document->createTextNode($childData));
} elseif (is_array($childData)) {
appendTo($node, $childData);
}
}
}
}
$document = new DOMDocument();
$document->formatOutput = TRUE;
appendTo($document, $data);
echo $document->saveXml();
Output:
<?xml version="1.0"?>
<account id="123456">
<name>BBC</name>
<monitors>
<monitor id="5235632">
<url>http://www.bbc.co.uk/</url>
</monitor>
<monitor id="5235633">
<url>http://www.bbc.co.uk/news</url>
</monitor>
</monitors>
</account>
Try the following function
function assocArrayToXML($root_element_name,$ar)
{
$xml = new SimpleXMLElement("<?xml version=\"1.0\"?><{$root_element_name}></{$root_element_name}>");
$f = function($f,$c,$a) {
foreach($a as $k=>$v) {
if(is_array($v)) {
$ch=$c->addChild($k);
$f($f,$ch,$v);
} else {
$c->addChild($k,$v);
}
}
};
$f($f,$xml,$ar);
return $xml->asXML();
}
echo assocArrayToXML("root",$data);
test it here
Hope this will help.
<?php
function array2xml($arr)
{
$dom = new DomDocument('1.0');
/*
*Create Root
*/
$root = $dom->createElement($arr['name']);
if(isset($arr['attr']) && !empty($arr['attr']))
{
foreach($arr['attr'] as $key=>$val)
$root->setAttribute($key, $val);
}
$root = $dom->appendChild($root);
createChilds($arr['children'], $dom, $root);
header('Content-type: text/xml');
echo $dom->saveXML();
}
function createChilds($arr, $dom, $parent)
{
foreach($arr as $child)
{
if(isset($child['name']))
$node = $dom->createElement($child['name']);
/*
*Add Attributes
*/
if(isset($child['attr']) && !empty($child['attr']))
{
foreach($child['attr'] as $key=>$val)
$node->setAttribute($key, $val);
}
/*
*Add Childs Recursively
*/
if(isset($child['children']) && is_array($child['children']))
{
createChilds($child['children'], $dom, $node);
}
else if(isset($child) && is_string($child))
{
$text = $dom->createTextNode($child);
$parent->appendChild($text);
}
if(isset($node))
$parent->appendChild($node);
}
}
$data = Array(
'name' => 'account',
'attr' => Array(
'id' => 123456
),
'children' => Array(
Array(
'name' => 'name',
'attr' => Array(),
'children' => Array(
'BBC'
),
),
Array(
'name' => 'monitors',
'attr' => Array(),
'children' => Array(
Array(
'name' => 'monitor',
'attr' => Array(
'id' => 5235632
),
'children' => Array(
Array(
'name' => 'url',
'attr' => Array(),
'children' => Array(
'http://www.bbc.co.uk/'
)
)
)
),
Array(
'name' => 'monitor',
'attr' => Array(
'id' => 5235633
),
'children' => Array(
Array(
'name' => 'url',
'attr' => Array(),
'children' => Array(
'http://www.bbc.co.uk/news'
)
)
)
)
)
)
)
);
array2xml($data);
?>
Related
I need to build a multidimensional array using foreach
There is an array with the names of social networks social_array()
the result should be like that:
array(
'type' => 'textfield',
'heading' => 'social_label1',
'param_name' => 'social_name1',
'description' => '',
'edit_field_class' => 'vc_col-sm-4 vc_column-with-padding',
'group' => __('Social', 'AS')
),
array(
'type' => 'textfield',
'heading' => 'social_label2',
'param_name' => 'social_name2',
'description' => '',
'edit_field_class' => 'vc_col-sm-4 vc_column-with-padding',
'group' => __('Social', 'AS')
),
...
etc
The problem is that my code gives me only one result, the last
foreach ( social_array() as $icon => $value ) :
$k = array('type', 'heading', 'param_name', 'description', 'edit_field_class', 'group');
$v = array('textfield', $value['label'], $icon, '', 'vc_col-sm-4 vc_column-with-padding', 'Social');
$c = array_combine($k, $v);
$attributes['params'] = $c;
endforeach;
vc_add_params( 'profile_card', $attributes ); // Note: base for element
Social if needed
function social_array(){
return array(
'facebook' => array('label' => __('Facebook','AS7'), 'type' => 'text' ),
'behance' => array('label' => __('Behance','AS7'), 'type' => 'text' ),
'weibo' => array('label' => __('Weibo','AS7'), 'type' => 'text' ),
'renren' => array('label' => __('Renren','AS7'), 'type' => 'text' ),
'dropbox' => array('label' => __('Dropbox','AS7'), 'type' => 'text' ),
'bitbucket' => array('label' => __('Bitbucket','AS7'), 'type' => 'text' ),
'trello' => array('label' => __('Trello','AS7'), 'type' => 'text' ),
'odnoklassniki' => array('label' => __('Odnoklassniki','AS7'), 'type' => 'text' ),
'vk' => array('label' => __('VKontakte','AS7'), 'type' => 'text' ),
);
}
You'll need 2 foreach loops for this because the first foreach loop gives you all the arrays inside it. then you need to access each array and loop over it.
foreach ( social_array() as $array) :
foreach ( $array as $icon => $value ):
//Do something with $icon and its $value
endforeach;
endforeach;
$attributes['params'] = $c;
This is the problem, on any cycle you're setting this value to $c, so in the last cycle you're setting $attributes to the latest $c.
If you want $attributes['params'] to contain all the arrays you need to use this syntax:
$attributes['params'][] = $c;
OR the same but with function call:
array_push($attributes['params'], $c);
maybe someone will come in handy this piece.
The working option is below.
The task was to dynamically add many of the same type of fields in the shortcode settings via Visual Composer and the vc_add_params() function
$attributes = array();
foreach ( social_array() as $icon => $value ) :
$k = array('type', 'heading', 'param_name', 'description', 'edit_field_class', 'group');
$v = array('textfield', $value['label'], 'as_'.$icon, '', 'vc_col-sm-4 vc_column-with-padding', 'Social');
$c = array_combine($k, $v);
$attributes[] = $c;
endforeach;
vc_add_params( 'as_profile_card', $attributes ); // Note: base for element
I have two arrays with nearly the same structure.
The first array is $_POST data while the second one holds regex rules and some other stuff for data validation.
Example:
$data = array(
'name' => 'John Doe',
'address' => array(
'city' => 'Somewhere far beyond'
)
);
$structure = array(
'address' => array(
'city' => array(
'regex' => 'someregex'
)
)
);
Now I want to check
$data['address']['city'] with $structure['address']['city']['regex']
or
$data['foo']['bar']['baz']['xyz'] with $structure['foo']['bar']['baz']['xyz']['regex']
Any ideas how to achieve this with a PHP function?
Edit: It seems that I found a solution by myself.
$data = array(
'name' => 'John Doe',
'address' => array(
'city' => 'Somewhere far beyond'
),
'mail' => 'test#test.tld'
);
$structure = array(
'address' => array(
'city' => array(
'regex' => 'some_city_regex1',
)
),
'mail' => array(
'regex' => 'some_mail_regex1',
)
);
function getRegex($data, $structure)
{
$return = false;
foreach ($data as $key => $value) {
if (empty($structure[$key])) {
continue;
}
if (is_array($value) && is_array($structure[$key])) {
getRegex($value, $structure[$key]);
}
else {
if (! empty($structure[$key]['regex'])) {
echo sprintf('Key "%s" with value "%s" will be checked with regex "%s"', $key, $value, $structure[$key]['regex']) . '<br>';
}
}
}
return $return;
}
getRegex($data, $structure);
Given these arrays:
$data = array(
'name' => 'John Doe',
'address' => array(
'city' => 'Somewhere far beyond'
),
'foo' => array(
'bar' => array(
'baz' => array(
'xyz' => 'hij'
)
)
)
);
$structure = array(
'address' => array(
'city' => array(
'regex' => '[a-Z]'
)
),
'foo' => array(
'bar' => array(
'baz' => array(
'xyz' => array(
'regex' => '[0-9]+'
)
)
)
)
);
and this function:
function validate ($data, $structure, &$validated) {
if (is_array($data)) {
foreach ($data as $key => &$value) {
if (
array_key_exists($key, $structure)
and is_array($structure[$key])
) {
if (array_key_exists('regex', $structure[$key])) {
if (!preg_match($structure[$key]['regex'])) {
$validated = false;
}
}
validate($value, $structure[$key], $validated);
}
}
}
}
you can check the arrays against each other and get a validation result like so:
$validated = true;
validate($data, $structure, $validated);
if ($validated) {
echo 'everything validates!';
}
else {
echo 'validation error';
}
Ah, you've found a solution. Very nice.
I want create a input type switch in my backend module in prestashop 1.6.
I write this and work
array(
'type' => 'switch',
'label' => $this->l('Label'),
'name' => 'PRESTASHOP_INPUT_SWITCH',
'is_bool' => true,
'desc' => $this->l('Description'),
'values' => array(
array(
'id' => 'active_on',
'value' => true,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => false,
'label' => $this->l('Disabled')
)
),
)
But if i try with custom value e not boolean it not work
array(
'type' => 'switch',
'label' => $this->l('Label'),
'name' => 'PRESTASHOP_INPUT_SWITCH',
'is_bool' => false,
'desc' => $this->l('Description'),
'values' => array(
array(
'id' => 'value1',
'value' => 'value1',
'label' => $this->l('value1')
),
array(
'id' => 'value2',
'value' => 'value2',
'label' => $this->l('value2')
)
),
)
In backend appear two boxes with labels value 'no'.
In HelperForm classes of prestashop there is no trace of input type switch.
The same code with type radio work, but i want a switch type.
Unfortunately, as you can see here:
PrestaShop doesn't have possibility to use custom value in "switch" field.
You don't need to change default switch values.
This is how you handle submit form:
public function getContent()
{
if (Tools::isSubmit('submitForm'))
{
$my_value = ( (int)Tools::getValue('PRESTASHOP_INPUT_SWITCH') == 1 ) ? 'value1' : 'value2';
if (Configuration::updateValue('PRESTASHOP_INPUT_SWITCH', $my_value))
$echo .= $this->displayConfirmation($this->l('Value updated.'));
}
$echo .= $this->renderForm();
return $echo;
}
You probably already have something like this:
public function renderForm()
{
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Settings'),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'switch',
'label' => $this->l('Label'),
'name' => 'PRESTASHOP_INPUT_SWITCH',
'is_bool' => true,
'desc' => $this->l('Description'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Value1')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Value2')
)
),
)
),
'submit' => array(
'title' => $this->l('Save'),
)
),
);
$helper = new HelperForm();
$helper->module = $this;
$helper->show_toolbar = false;
$helper->table = $this->table;
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$this->fields_form = array();
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitForm';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFieldsValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
return $helper->generateForm(array($fields_form));
}
and loading the values:
public function getConfigFieldsValues()
{
return array(
'PRESTASHOP_INPUT_SWITCH' => Tools::getValue('PRESTASHOP_INPUT_SWITCH', Configuration::get('PRESTASHOP_INPUT_SWITCH') == 'value1' : 1 : 0),
);
}
Unfortunately prestashop doesn't support the custom value of switch but you can handle this like:
$config = Configuration::get('oneclickcheckout');
$this->settings = Tools::unSerialize($config);
$settings = $this->settings;
if (isset($settings['Description']) && $settings['Description'] == 1) {
}
This question already has an answer here:
How to convert XML into PHP array? [duplicate]
(1 answer)
Closed 8 years ago.
Follow up question to this How to convert properly the xml radio into php array
I have a format of xml (output) and I want to convert it into PHP Array (input). But my codes it's not working, it only display the whole code of my array when I try to run it.
How to do the right conversion?
I have this xml with radio button:
<?xml version="1.0" encoding="UTF-8"?>
<Form xmlns="url" label="Home Visit Form" type="TextView" name="Form">
<Field name="ClientRelation" label="Client" value="Kamosi" type="TextView"/>
<Field name="ContactNum" label="ContactNum" value="12345678" type="TextView"/>
<Field name="Address" label="Address" value="tes" type="TextView"/>
<Field name="Landmark" label="Landmark" value="Pred dubem, za dubem" type="TextView"/>
<Field type="Delimiter"/>
<Field name="CP_RESULT" label="Cash pick-up result" value="CP_RESULT_PAID_TO_VISITOR" type="Radio">
<Item code="CP_RESULT_PAID_TO_VISITOR" label="Client paid to field visitor"/>
<Item code="CP_RESULT_PAID_THRU_PMT_CHANNEL" label="Client paid through payment channel"/>
<Item code="CP_RESULT_CLIENT_NOT_AVAIL" label="Client not available"/>
<Item code="CP_RESULT_CLIENT_CAN_NOT_PAY" label="Client can not pay"/>
</Field>
<Field name="CP_INFO_FROM_PAYEE" label="Notes" value="fgjjk" type="EditText" format="string"/>
<Field name="CP_PICTURE_RECEIPT" label="Receipt picture" value="Cash Pick-up 3400888888-CP_PICTURE_RECEIPT.jpg" type="Picture" format="string"/>
<Field name="CP_PICTURE_PLACE" label="Place picture (outdoor)" value="Cash Pick-up 3400888888-CP_PICTURE_PLACE.jpg" type="Picture" format="string"/>
</Form>
PHP Array:
require_once('XMLtoArray.php');
$Example1= array();
$Example1['#attributes'] = array(
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
'xsi:noNamespaceSchemaLocation' => 'url',
'label'=> 'Form',
'type' => 'TextView',
'name' => 'Form1'
);
'Field' => array(
array(
'#attributes' => array(
'name' => 'ClientRelation'
'label => 'test'
'value' => '',
'type' => 'TextView'
),
array(
'#attributes' => array(
'name' => '(
'name' => 'ContactNum'
'label => 'ContactNum'
'value' => '',
'type' => 'TextView'
),
array(
'#attributes' => array(
'name' => 'Address'
'label => 'Address'
'value' => '',
'type' => 'TextView'
),
array(
'#attributes' => array(
'name' => 'Landmark'
'label => 'Landmark'
'value' => '',
'type' => 'TextView'
),
array(
'#attributes' =>(
'type' = > 'Delimiter'
),
array(
'#attributes' => array(
'name' => 'CP_RESULT'
'label => 'Cash pick-up result'
'value' => '',
'type' => 'Radio'
),
'Item' => array(
array(
'#attributes' => array(
'code' => 'CP_RESULT_PAID_TO_VISITOR',
'label' => 'Client paid to field visitor',
),
array(
'#attributes' => array(
'code' => 'CP_RESULT_PAID_THRU_PMT_CHANNEL',
'label' => 'Client paid through payment channel',
),
array(
'#attributes' => array(
'code' => 'CP_RESULT_CLIENT_NOT_AVAIL',
'label' => 'Client not available',
),
array(
'#attributes' => array(
'code' => 'CP_RESULT_CLIENT_CAN_NOT_PAY',
'label' => 'Client can not pay',
);
array(
'#attributes' => array(
'name' => 'CP_PICKED_AMOUNT'
'label => 'Picked Amount'
'value' => '',
'type' => 'EditText',
'format' => 'string'
),
array(
'#attributes' => array(
'name' => '(
'name' => 'CP_VISIT_DATE'
'label => 'Date of Pick-up'
'value' => '',
'type' => 'EditText',
'format' => 'string'
),
array(
'#attributes' => array(
'name' => 'CP_VISIT_TIME'
'label => 'Time of Pick-up'
'value' => '',
'type' => 'EditText',
'format' => 'string'
),
array(
'#attributes' => array(
'name' => 'CP_REASON_CODE'
'label => 'Reason Code'
'value' => '',
'type' => 'EditText',
'format' => 'string'
),
array(
'#attributes' => array(
'name' => '(
'name' => 'CP_NOTES'
'label => 'Notes'
'value' => '',
'type' => 'EditText',
'format' => 'string'
),
array(
'#attributes' => array(
'name' => 'CP_RECEIPT_NUMBER'
'label => 'Receipt number'
'value' => '',
'type' => 'EditText',
'format' => 'string'
),
array(
'#attributes' => array(
'name' => 'CP_INFO_FROM_PAYEE'
'label => 'Notes'
'value' => '',
'type' => 'EditText',
'format' => 'string'
),
array(
'#attributes' => array(
'name' => 'CP_PICTURE_RECEIPT'
'label => 'Receipt picture'
'value' => '',
'type' => 'Picture
'format' => 'string'
),
array(
'#attributes' => array(
'name' => 'CP_PICTURE_PLACE'
'label => 'Place picture (outdoor)'
'value' => '',
'type' => 'Picture',
'format' => 'string'
);
$xml = Array2XML::createXML('CashPickUp', $CashPickUp);
echo $xml->saveXML();
?>
XMLtoArray.php
<?php
class XML2Array {
private static $xml = null;
private static $encoding = 'UTF-8';
public static function init($version = '1.0', $encoding = 'UTF-8', $format_output = true) {
self::$xml = new DOMDocument($version, $encoding);
self::$xml->formatOutput = $format_output;
self::$encoding = $encoding;
}
public static function &createArray($input_xml) {
$xml = self::getXMLRoot();
if(is_string($input_xml)) {
$parsed = $xml->loadXML($input_xml);
if(!$parsed) {
throw new Exception('[XML2Array] Error parsing the XML string.');
}
} else {
if(get_class($input_xml) != 'DOMDocument') {
throw new Exception('[XML2Array] The input XML object should be of type: DOMDocument.');
}
$xml = self::$xml = $input_xml;
}
$array[$xml->documentElement->tagName] = self::convert($xml->documentElement);
self::$xml = null; // clear the xml node in the class for 2nd time use.
return $array;
}
private static function &convert($node) {
$output = array();
switch ($node->nodeType) {
case XML_CDATA_SECTION_NODE:
$output['#cdata'] = trim($node->textContent);
break;
case XML_TEXT_NODE:
$output = trim($node->textContent);
break;
case XML_ELEMENT_NODE:
// for each child node, call the covert function recursively
for ($i=0, $m=$node->childNodes->length; $i<$m; $i++) {
$child = $node->childNodes->item($i);
$v = self::convert($child);
if(isset($child->tagName)) {
$t = $child->tagName;
// assume more nodes of same kind are coming
if(!isset($output[$t])) {
$output[$t] = array();
}
$output[$t][] = $v;
} else {
//check if it is not an empty text node
if($v !== '') {
$output = $v;
}
}
}
if(is_array($output)) {
// if only one node of its kind, assign it directly instead if array($value);
foreach ($output as $t => $v) {
if(is_array($v) && count($v)==1) {
$output[$t] = $v[0];
}
}
if(empty($output)) {
//for empty nodes
$output = '';
}
}
// loop through the attributes and collect them
if($node->attributes->length) {
$a = array();
foreach($node->attributes as $attrName => $attrNode) {
$a[$attrName] = (string) $attrNode->value;
}
// if its an leaf node, store the value in #value instead of directly storing it.
if(!is_array($output)) {
$output = array('#value' => $output);
}
$output['#attributes'] = $a;
}
break;
}
return $output;
}
/*
* Get the root XML node, if there isn't one, create it.
*/
private static function getXMLRoot(){
if(empty(self::$xml)) {
self::init();
}
return self::$xml;
}
}
?>
What about simple:
$xml = simplexml_load_string($xmlstring);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
According to https://stackoverflow.com/a/20431742/1856120
I have this array:
$all = array(
'meat' => Object(
'name' => 'meat',
'color' => 'red',
'class' => 'food'
),
'chicken' => Object(
'name' => 'chicken',
'color' => 'white',
'class' => 'food'
),
'apple' => Object(
'name' => 'apple',
'color' => 'green',
'class' => 'Fruit'
),
'blueberry' => Object(
'name' => 'blueberry',
'color' => 'blue',
'class' => 'Fruit'
)
);
and i want to Sort it and rebuild it to be like this:
$theright = array(
array(
'class' => 'food',
'menu' => array(
array(
'name' => 'meat',
'color' => 'red',
),
array(
'name' => 'chicken',
'color' => 'white',
)
)
),
array(
'class' => 'Fruit',
'menu' => array(
array(
'name' => 'apple',
'color' => 'green',
),
array(
'name' => 'blueberry',
'color' => 'blue',
)
)
)
);
I tried to Collect all classes in$all array then compare each value with $all array:
$classArray = array();
foreach($all as $key => $value) {
$classArray[$value->class] = array();
}
foreach($classArray as $key => $value) {
$theright[] = array('class' => $key, 'menu' => array());
}
this code get me this array:
$theright = array(
array(
'class' => 'food',
'menu' => array()
),
array(
'class' => 'Fruit',
'menu' => array()
)
);
and i stop here , how to complete it ?
You could just use the class as a key to group them together. Example:
$food = array();
// gather class
foreach($all as $item) {
if(!isset($food[$item->class])) {
$food[$item->class] = array(
'class' => $item->class,
'menu' => array(
array(
'name' => $item->name,
'color' => $item->name,
)
)
);
} else {
$food[$item->class]['menu'][] = array('name' => $item->name,'color' => $item->color,);
}
}
// simple reindex
$food = array_values($food);
There is no need for a second loop. This should do what you want.
$classMap = array();
foreach ($all as $item)
{
// check if class has been created in the class map
if ( ! array_key_exists($classMap, $item['class']))
{
$classMap[$item['class']] = array(
'class' => $item['class'],
'menu' => array()
);
}
$classMap[$item['class']]['menu'][] = array(
'name' => $item['name'],
'color' => $item['color']
);
}
Try with less loop counts (2)
$all = [];
function getSelectClassData(array &$all)
{
$finalArr = [];
while (count($all) > 1) {
$res = [];
$class = array_values($all)[0]->class;
$selectedDataArr = getSelectSimilerMenuData($all, $class);
$res['class'] = $class;
$res['menu'] = array_values($selectedDataArr);
$all = array_diff_key($all,array_flip(array_keys($selectedDataArr)));
$finalArr[] = $res;
}
return $finalArr;
}
function getSelectSimilerMenuData(array $all, $class)
{
return array_filter(
$all,
function ($e) use ($class) {
return $e->class == $class;
}
);
}
print_r(getSelectClassData($all));