Jump to content

How extract arrays from array depend on values


demohat2017

Recommended Posts

My array is

$arr = array(
	'global' => array(
		array('tabs', 'tabs', 'tabs', array(
			'Main' => 'main',
			'Gallery' => 'galleryID',
			'mera' => 'mera',
		)),

		array('main','div',  'div'),
		array('egice', 'Eice', 'text', '', ''),
		array('closeHere', 'closeHere', 'closeHere'),


		array('galleryID','div',  'div'),
		array('gallery', 'Gallery #1', 'image', '', ''),
		array('closeHere', 'closeHere', 'closeHere'),


		array('networking', 'div', 'div'),
		array('siLype', 'SiLype', 'text', '', ''),
		array('gpXCge', 'GpXCge',  'toggle_button', '1', 'Yes', 'No', ''),
		array('closeHere', 'closeHere', 'closeHere'),


		array('mera', 'div', 'div'),
		array('maimera', 'Maimera', 'repeatedText', 'resYI', 'GYL',''),
		array('closeHere', 'closeHere', 'closeHere'),



		array( 'moures','div', 'div'),
		array('meLmo', 'MeLmo', 'text', '', ''),
		array('cYSlot', 'CYSlot', 'text', '', ''),
		array('closeHere', 'closeHere', 'closeHere'),

		array('clT', 'clT', 'clT'),



	),

);

Simply, I want to split the main array to multiple arrays
extract new Array if “div” value found

I had tried here to do it but I can’t
https://3v4l.org/ppj1O 1
Could you help?

Link to comment
Share on other sites

Look more closely at the array you have to work with. $arr is an array, containing a "global" that is an array, containing a bunch more arrays, some of which have "div" in them.

Now look at your code, which I'm going to paste here so that people don't have to go somewhere else on the internet to find it:

$split = [];
$i = 0;
foreach($arr as $k => $v) {
    if ($v == 'div') {
        $i++;
    }
    $split[$i][$k] = $v;
}

Your code looks at what's in $arr and tries to find anything that is the string "div".

Your array and your code are pretty far apart.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.