i am trying to do one thig ,but i am not getting the point.can anyone please suggests me ..
two dimensional array like below
$array = Array
([1] => Array
([1] => EST_ID
[2] => EST_CODE
[3] => EST_EXT
[4] => EST_NAME
[5] => INCROP_ADDRESS1
[6] => INCROP_ADDRESS2
[7] => INCROP_CITY
[8] => INCROP_DIST
[9] => INCROP_STATE
[10] => INCROP_PIN
)
[2] => Array
([1] => HRKNL0006923000
[2] => 6923
[4] => VAIBHAV CARPETS
[5] => BHUL-BHULIA CHOWK
[6] => BODHWA RAM COLONY
[7] => PANIPAT
[8] => PANIPAT
[10] => 132103)
[3] => Array
([1] => HRKNL0004638000
[2] => 4638
[4] => GURU TEG BHADUR PUBLIC SCHOOL
[5] => MODEL TOWN
[6] => KARNAL
[7] => KARNAL
[8] => KARNAL
[10] => 132001)
)
i have to search the array key of either 2 or 3 from $array
Not exactly sure which one you need as I didn't fully understand the question but one of these two functions will help array_key_exists() or in_array()
It sounds like you may be trying to do what I asked in Search a multi-dimensional array for certain values
Related
I have 4 arrays with each 10 elements:
$vidtype = Array ( [0] => Array ( [0] => Sales [1] => Sales [2] => Sales [3] => Sales [4] => Sales [5] => Sales [6] => Sales [7] => Sales [8] => Sales [9] => Sales
$vidcategory = Array ( [0] => Array ( [0] => comfortsystemen [1] => multimediasystemen [2] => assistentiesystemen [3] => multimediasystemen [4] => productfilms [5] => assistentiesystemen [6] => multimediasystemen [7] => productfilms [8] => productfilms [9] => productfilms
$vidurl = Array ( [0] => Array ( [0] => www.youtube.com/video/bOejnFiC88E [1] => www.youtube.com/video/FsVAxrvi6iE [2] => www.youtube.com/video/3lGfTZdVK1s [3] => www.youtube.com/video/hcw8dl73-W4 [4] => www.youtube.com/video/NlHJ5njWVFE [5] => www.youtube.com/video/II68oVm4zro [6] => www.youtube.com/video/tpg9IaOfno4 [7] => www.youtube.com/video/mzbG0JAICu8 [8] => www.youtube.com/video/OgPodRbJ3So [9] => www.youtube.com/video/YfPLB30MSCU
$vidtitle = Array ( [0] => Array ( [0] => Gesture Control [1] => Volkswagen – Parkmobile [2] => Multi Collision braking system [3] => Mobiele telefoon interface Premium [4] => Maps & More Dock in de up! [5] => Lane Assist [6] => Car-Net Connect [7] => Volkswagen Allesdrager [8] => Volkswagen Bagagebox [9] => Volkswagen fietsendrager
The arrays are all in the same order, so value 1 of $vidtype matches value 1 of $vidcategory,$vidurl and $vidtitle. I am exporting them to an excel file but want to sort $vidtype and $vidtitle in alphabetical order.
If I do that the array values won't match anymore, so my idea was to merge all the values with the same key together and sort $vidtype and $vidtitle in alphabetical order after merging. So the values will still match.
I got stuck on the merge part, I have been searching on stackoverflow for a long time but couldn't find the right answer.
Is my idea clear? Any thoughts?
this will work
$abc=array();
for($i=0;$i<10;$i++){
$abc[$i]=array($vidtype[$i],$vidcategory[$i],$vidurl[$i],$vidtitle[$i]);
}
my code is:
array set 1:
Array
(
[0] => 15-3
[1] => 16-3
[2] => 15-4
[3] => 16-4
[4] => 15-3
[5] => 16-3
[6] => 15-4
[7] => 16-4
[8] => 15-3
[9] => 16-3
[10] => 15-4
[11] => 16-4
)
My second array set is:
Array
(
[0] => 1
[1] => 1
[2] => 1
[3] => 1
[4] => 2
[5] => 2
[6] => 2
[7] => 2
[8] => 3
[9] => 3
[10] => 3
[11] => 3
)
i just combine the above both the two array into one like below
$data1=array_combine($store_attri_ids, $store_ids);
but its shows like that
Array
(
[15-3] => 3
[16-3] => 3
[15-4] => 3
[16-4] => 3
)
The remaining values are not combined, wt we do nw????
You can try this by creating a sub-array -
$data1 = array();
foreach($store_attri_ids as $key => $id) {
$data1[$id][] = $store_ids[$key];
}
The output would be like -
Array
(
[15-3] => array(1, 2, 3),
[16-3] => array(...),
[15-4] => array(...),
[16-4] => array(...)
)
If you use array_combine the result is totally correct, like putting here: http://php.net/manual/en/function.array-combine.php
You need use array_merge, take a look at the documentation :http://php.net/manual/en/function.array-merge.php
Use like this:
$data1=array_merge($store_attri_ids, $store_ids);
print_r($data1);
I have a multidimensional array that look like this:
Array
[1] => Array
(
[0] => ACURA
[1] => CL
[2] => 3.2L V6 F/I
[3] => Blue
[4] => 33-2133
[5] => 33-2133
[6] => V6
[7] => F/I
[8] =>
)
[2] => Array
(
[0] => ACURA
[1] => CL
[2] => 3.2L V6 F/I
[3] => Blue
[4] => PS-1004
[5] => PS-1004
[6] => V6
[7] => F/I
[8] =>
)
)
I then have another array that looks like
Array
(
[0] => ACURA
[1] => CL
[2] => 3.2L V6 F/I
[3] => blue
[4] => HP-1004
[5] => HP-1004
[6] => V6
[7] => F/I
[8] =>
)
Is the a way to look through the multdimensional array and see if the single array exists already in the multidimensional array?
I believe in_array() should work.
Link to PHP manual.
In the changlog it mentions that as of 4.2.0 the needle (search) can be an array...
Well I have a PHP array like this:
Array
(
[0] => post9.post
[3] => post8.post
[4] => post4.post
[5] => post7.post
[6] => post5.post
[7] => post10.post
[8] => post3.post
[9] => post6.post
[10] => post1.post
[11] => post2.post
)
But after trying all the PHP array functions I don't manage to sort it in this way:
Array
(
[0] => post10.post
[1] => post9.post
[2] => post8.post
[3] => post7.post
[4] => post6.post
[5] => post5.post
[6] => post4.post
[7] => post3.post
[8] => post2.post
[9] => post1.post
)
I already made a question like this, which seemed to work but now it doesn't works :(
EDIT: After using rsortit looks like this:
Array
(
[0] => post9.post
[1] => post8.post
[2] => post7.post
[3] => post6.post
[4] => post5.post
[5] => post4.post
[6] => post3.post
[7] => post2.post
[8] => post10.post
[9] => post1.post
)
Almost good, except that post10.post should be [0] and is [8]
You need to use natsort and then reverse the order.
natsort($array);
$array = array_reverse($array);
i have the following array and want to get rid/remove the empty array and rearrange it in an order.can anyone help me please.
Array
(
[ufile] => Array
(
[name] => Array
(
[0] => chicken soup.jpg
[1] =>
[2] => hot n sour sup.jpg
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
)
[type] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
)
[tmp_name] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
)
[error] => Array
(
[0] => 1
[1] => 4
[2] => 1
[3] => 4
[4] => 4
[5] => 4
[6] => 4
[7] => 4
[8] => 4
)
[size] => Array
(
[0] => 0
[1] => 0
[2] => 0
[3] => 0
[4] => 0
[5] => 0
[6] => 0
[7] => 0
[8] => 0
)
)
)
I believe this will cleanup your array: remove empty elements (those that evaluate to empty, eg "" and 0 equally), remove duplicate elements, and sort it.
$cleaned = array_map('array_filter', $array_to_be_cleaned);
$cleaned = array_map('array_unique', $cleaned);
$cleaned = array_map('sort', $cleaned);
To filter out the empty elements of the array, check out array_filter.
To sort the elements, check out sort (or refer to this list of sorting functions to see what meets your needs)
$newarray = array_filter($myarray);
sort($newarray);
This will take the array you pass it (ie. $myarray) and it will strip out any empty values, then it will store the results to $newarray. After that, sort will organize the remaining values from least to greatest.
unset( $var['ufile']['type'] );
unset( $var['ufile']['tmp_name'] );
To sort, use sort(), usort(), or any other you want. Here's a good comparison of the different sort methods.
Try array_filter($array). It will remove all NULL elements and return the cleared array.