Wrong result for array_count_values in PHP - php

I have an array like this -
Array ( [0] => একটু [1] => আরো [2] => নয় [3] => কাছে [4] => থাকো [5] => না [6] => কাছে [7] => ডাকো [8] => না [9] => আরো [10] => কাছে [11] => আজ [12] => দুজনের [13] => প্রথম [14] => মিলনের [15] => চাঁদ [16] => তারা [17] => ঐ [18] => সাক্ষী [19] => আছে [20] => তুমি [21] => আমার [22] => আমি [23] => তোমার [24] => [25] => মন [26] => যে [27] => ভরেছে [28] => জোছনা [29] => ঝরেছে [30] => পৃথিবী [31] => দ্যাখো [32] => ঐ [33] => ঘুমিয়ে [34] => পড়েছে [35] => মন [36] => যে [37] => ভরেছে [38] => জোছনা [39] => ঝরেছে [40] => পৃথিবী [41] => দ্যাখো [42] => ঐ [43] => ঘুমিয়ে [44] => পড়েছে [45] => আমি [46] => তোমার [47] => তুমি [48] => আমার [49] => একটু [50] => আরো [51] => নয় [52] => কাছে [53] => থাকো [54] => না [55] => কাছে [56] => ডাকো [57] => না [58] => আরো [59] => কাছে [60] => আমি [61] => তোমার [62] => তুমি [63] => আমার [64] => [65] => ফুলেরই [66] => হাসিতে [67] => হাওয়ার [68] => বাঁশিতে [69] => এ [70] => রাত [71] => শেখালো [72] => ভালো [73] => যে [74] => বাসিতে [75] => আমি [76] => তোমার [77] => তুমি [78] => আমার [79] => একটু [80] => আরো [81] => নয় [82] => কাছে [83] => থাকো [84] => না [85] => কাছে [86] => ডাকো [87] => না [88] => আরো [89] => কাছে [90] => তুমি [91] => আমার [92] => আমি [93] => তোমার [94] => )
When i am counting the same values using the following code it is giving wrong results like below -
$wordCountArr = array_count_values($matchWords);
Array ( [একটু] => 1 [আরো] => 6 [নয়] => 3 [কাছে] => 6 [থাকো] => 3 [না]
=> 6 [ কাছে] => 3 [ডাকো] => 3 [ আজ] => 1 [দুজনের] => 1 [প্রথম] => 1 [মিলনের] => 1 [ চাঁদ] => 1 [তারা] => 1 [ঐ] => 3 [সাক্ষী] => 1 [আছে] =>
1 [ তুমি] => 2 [আমার] => 5 [আমি] => 2 [তোমার] => 5 [] => 3 [ মন] => 1
[যে] => 3 [ভরেছে] => 2 [জোছনা] => 2 [ঝরেছে] => 2 [ পৃথিবী] => 2
[দ্যাখো] => 2 [ঘুমিয়ে] => 2 [পড়েছে] => 2 [ মন] => 1 [ আমি] => 3 [তুমি]
=> 3 [ একটু] => 2 [ ফুলেরই] => 1 [হাসিতে] => 1 [হাওয়ার] => 1 [বাঁশিতে] => 1 [ এ] => 1 [রাত] => 1 [শেখালো] => 1 [ভালো] => 1 [বাসিতে] => 1 )
But why [কাছে] => 6 and [ কাছে] => 3 ??? It suppose to be [কাছে] => 9
Now should i trim the spaces before and after or match words with spaces ? I used array_map('trim',$matchWords) but no luck!
How can i fix this? Please HELP !

Yes the matching is separate for those because of the space. trim() to remove spaces for each word wouldn't work for your case as it doesn't remove unicode white spaces.
So your solution use: preg_replace.
Refer:
Trim unicode whitespace
why is php trim is not really remove all whitespace and line breaks?

Related

Last element of array

Im trying to go through array to create a new one from it. Trying to log everything while runnging this code:
$this->writeToLog(print_r($this->assembledText, true), 'ass.log');
foreach ($this->assembledText as $paragraphsKey => $paragraphs) {
$this->writeToLog("Paragraph Key:".$paragraphsKey.print_r($paragraphs, true), 'para.log');
$i = 0;
foreach ($paragraphs as $words) {
$newText[$paragraphsKey][$i] = $words;
$i++;
}
}
Here Im logging the text before i go through, and here what i have so far:
ass.log gives me this:
[2019-05-18 20:32:38] Array
(
[0] => Array
(
[0] => One
[1] => thing
[2] => was
[3] => certain,
[4] => that
[5] => the
[6] => white
[7] => kitten
[8] => had
[9] => had
[10] => nothing
[11] => to
[12] => do
[13] => with
[14] => it:
[15] => —
[16] => it
[17] => was
[18] => the
[19] => black
[20] => kitten’s
[21] => fault
[22] => entirely.
[23] => For
[24] => the
[25] => white
[26] => kitten
[27] => had
[28] => been
[29] => having
[30] => its
[31] => face
[32] => washed
[33] => by
[34] => the
[35] => old
[36] => cat
[37] => for
[38] => the
[39] => last
[40] => quarter
[41] => of
[42] => an
[43] => hour
[44] => (and
[45] => bearing
[46] => it
[47] => pretty
[48] => well,
[49] => considering);
[50] => so
[51] => you
[52] => see
[53] => that
[54] => it
[55] => couldn’t
[56] => have
[57] => had
[58] => any
[59] => hand in
[61] => the
[62] => mischief.
[63] =>
)
[1] => Array
(
[0] =>
[1] => The
[2] => way
[3] => Dinah
[4] => washed
[5] => her
[6] => children’s
[7] => faces
[8] => was
[9] => this:
[10] => first
[11] => she
[12] => held
[13] => the
[14] => poor
[15] => thing
[16] => down
[17] => by
[18] => its
[19] => ear
[20] => with
[21] => one
[22] => paw,
[23] => and
[24] => then
[25] => with
[26] => the
[27] => other
[28] => paw
[29] => she
[30] => rubbed
[31] => its
[32] => face
[33] => all
[34] => over,
[35] => the
[36] => wrong
[37] => way,
[38] => beginning
[39] => at
[40] => the
[41] => nose:
[42] => and
[43] => just
[44] => now,
[45] => as
[46] => I
[47] => said,
[48] => she
[49] => was
[50] => hard
[51] => at
[52] => work on
[54] => the
[55] => white
[56] => kitten,
[57] => which
[58] => was
[59] => lying
[60] => quite
[61] => still
[62] => and
[63] => trying
[64] => to
[65] => purr
[66] => —
[67] => no
[68] => doubt
[69] => feeling
[70] => that
[71] => it
[72] => was
[73] => all
[74] => meant
[75] => for
[76] => its
[77] => good.
[78] =>
)
[2] => Array
(
[0] =>
[1] => But
[2] => the
[3] => black
[4] => kitten
[5] => had
[6] => been
[7] => finished
[8] => with
[9] => earlier
[10] => in
[11] => the
[12] => afternoon,
[13] => and
[14] => so,
[15] => while
[16] => Alice
[17] => was
[18] => sitting
[19] => curled
[20] => up
[21] => in
[22] => a
[23] => corner
[24] => of
[25] => the
[26] => great
[27] => arm-chair,
[28] => half
[29] => talking
[30] => to
[31] => herself
[32] => and
[33] => half
[34] => asleep,
[35] => the
[36] => kitten
[37] => had
[38] => been
[39] => having
[40] => a
[41] => grand
[42] => game
[43] => of
[44] => romps
[45] => with
[46] => the
[47] => ball
[48] => of
[49] => worsted
[50] => Alice
[51] => had
[52] => been
[53] => trying
[54] => to
[55] => wind up,
[57] => and
[58] => had
[59] => been
[60] => rolling
[61] => it
[62] => up
[63] => and
[64] => down
[65] => till
[66] => it
[67] => had
[68] => all
[69] => come
[70] => undone
[71] => again;
[72] => and
[73] => there
[74] => it
[75] => was,
[76] => spread
[77] => over
[78] => the
[79] => hearth-rug,
[80] => all
[81] => knots
[82] => and
[83] => tangles,
[84] => with
[85] => the
[86] => kitten
[87] => running
[88] => after
[89] => its
[90] => own
[91] => tail
[93] => the
[94] => middle.
[95] =>
)
[3] => Array
(
[0] =>
[1] => ‘Oh,
[2] => you
[3] => wicked
[4] => little
[5] => thing!’
[6] => cried
[7] => Alice,
[8] => catching up
[10] => the
[11] => kitten,
[12] => and
[13] => giving
[14] => it
[15] => a
[16] => little
[17] => kiss
[18] => to
[19] => make
[20] => it
[21] => understand
[22] => that
[23] => it
[24] => was
[25] => in
[26] => disgrace.
[27] =>
)
)
And para.log gives me this, like i dont have the last element of array, but i do have an index:
[2019-05-18 20:32:38] Paragraph Key:0Array
(
[0] => One
[1] => thing
[2] => was
[3] => certain,
[4] => that
[5] => the
[6] => white
[7] => kitten
[8] => had
[9] => had
[10] => nothing
[11] => to
[12] => do
[13] => with
[14] => it:
[15] => —
[16] => it
[17] => was
[18] => the
[19] => black
[20] => kitten’s
[21] => fault
[22] => entirely.
[23] => For
[24] => the
[25] => white
[26] => kitten
[27] => had
[28] => been
[29] => having
[30] => its
[31] => face
[32] => washed
[33] => by
[34] => the
[35] => old
[36] => cat
[37] => for
[38] => the
[39] => last
[40] => quarter
[41] => of
[42] => an
[43] => hour
[44] => (and
[45] => bearing
[46] => it
[47] => pretty
[48] => well,
[49] => considering);
[50] => so
[51] => you
[52] => see
[53] => that
[54] => it
[55] => couldn’t
[56] => have
[57] => had
[58] => any
[59] => hand in
[61] => the
[62] => mischief.
[63] =>
)
[2019-05-18 20:32:38] Paragraph Key:1Array
(
[0] =>
[1] => The
[2] => way
[3] => Dinah
[4] => washed
[5] => her
[6] => children’s
[7] => faces
[8] => was
[9] => this:
[10] => first
[11] => she
[12] => held
[13] => the
[14] => poor
[15] => thing
[16] => down
[17] => by
[18] => its
[19] => ear
[20] => with
[21] => one
[22] => paw,
[23] => and
[24] => then
[25] => with
[26] => the
[27] => other
[28] => paw
[29] => she
[30] => rubbed
[31] => its
[32] => face
[33] => all
[34] => over,
[35] => the
[36] => wrong
[37] => way,
[38] => beginning
[39] => at
[40] => the
[41] => nose:
[42] => and
[43] => just
[44] => now,
[45] => as
[46] => I
[47] => said,
[48] => she
[49] => was
[50] => hard
[51] => at
[52] => work on
[54] => the
[55] => white
[56] => kitten,
[57] => which
[58] => was
[59] => lying
[60] => quite
[61] => still
[62] => and
[63] => trying
[64] => to
[65] => purr
[66] => —
[67] => no
[68] => doubt
[69] => feeling
[70] => that
[71] => it
[72] => was
[73] => all
[74] => meant
[75] => for
[76] => its
[77] => good.
[78] =>
)
[2019-05-18 20:32:38] Paragraph Key:2Array
(
[0] =>
[1] => But
[2] => the
[3] => black
[4] => kitten
[5] => had
[6] => been
[7] => finished
[8] => with
[9] => earlier
[10] => in
[11] => the
[12] => afternoon,
[13] => and
[14] => so,
[15] => while
[16] => Alice
[17] => was
[18] => sitting
[19] => curled
[20] => up
[21] => in
[22] => a
[23] => corner
[24] => of
[25] => the
[26] => great
[27] => arm-chair,
[28] => half
[29] => talking
[30] => to
[31] => herself
[32] => and
[33] => half
[34] => asleep,
[35] => the
[36] => kitten
[37] => had
[38] => been
[39] => having
[40] => a
[41] => grand
[42] => game
[43] => of
[44] => romps
[45] => with
[46] => the
[47] => ball
[48] => of
[49] => worsted
[50] => Alice
[51] => had
[52] => been
[53] => trying
[54] => to
[55] => wind up,
[57] => and
[58] => had
[59] => been
[60] => rolling
[61] => it
[62] => up
[63] => and
[64] => down
[65] => till
[66] => it
[67] => had
[68] => all
[69] => come
[70] => undone
[71] => again;
[72] => and
[73] => there
[74] => it
[75] => was,
[76] => spread
[77] => over
[78] => the
[79] => hearth-rug,
[80] => all
[81] => knots
[82] => and
[83] => tangles,
[84] => with
[85] => the
[86] => kitten
[87] => running
[88] => after
[89] => its
[90] => own
[91] => tail
[93] => the
[94] => middle.
[95] =>
)
[2019-05-18 20:32:38] Paragraph Key:3
Any suggestions?
So, i found the solution in the php Bug report: https://bugs.php.net/bug.php?id=60534
Which means that i have to use & (reference) even if i don't need it, just to avoid this bug
PHP version 5.6.33

warning illegal string offset while fetching result from database

I am using the following code to find the data from database
echo $query = "select * from `oc_order` where `store_url`='' ORDER BY `order_id` DESC LIMIT 5";
$mysqlq = mysqli_query($connection,$query) or die(mysqli_error($connection));
$mysqlw = mysqli_fetch_array($mysqlq);
echo "<pre>";
print_r($mysqlw);
foreach($mysqlw as $mysqlw)
{
echo $mysqlw['telephone'];
}
?>
I am getting the following array
Array
(
[0] => 73
[order_id] => 73
[1] => 0
[invoice_no] => 0
[2] =>
[invoice_prefix] =>
[3] => 0
[store_id] => 0
[4] =>
[store_name] =>
[5] =>
[store_url] =>
[6] => 9
[customer_id] => 9
[7] => 1
[customer_group_id] => 1
[8] => T****
[firstname] => ****
[9] =>
[lastname] =>
[10] => ********
[email] => *******
[11] => *****
[telephone] => *****
[12] =>
[fax] =>
[13] => 364ce6e2003bb1404f34
[custom_field] => 364ce6e2003bb1404f34
[14] =>
[payment_firstname] =>
[15] =>
[payment_lastname] =>
[16] =>
[payment_company] =>
[17] =>
[payment_address_1] =>
[18] =>
[payment_address_2] =>
[19] =>
[payment_city] =>
[20] =>
[payment_postcode] =>
[21] =>
[payment_country] =>
[22] => 0
[payment_country_id] => 0
[23] =>
[payment_zone] =>
[24] => 0
[payment_zone_id] => 0
[25] =>
[payment_address_format] =>
[26] =>
[payment_custom_field] =>
[27] =>
[payment_method] =>
[28] =>
[payment_code] =>
[29] =>
[shipping_firstname] =>
[30] =>
[shipping_lastname] =>
[31] =>
[shipping_company] =>
[32] =>
[shipping_address_1] =>
[33] =>
[shipping_address_2] =>
[34] =>
[shipping_city] =>
[35] =>
[shipping_postcode] =>
[36] =>
[shipping_country] =>
[37] => 0
[shipping_country_id] => 0
[38] =>
[shipping_zone] =>
[39] => 0
[shipping_zone_id] => 0
[40] =>
[shipping_address_format] =>
[41] =>
[shipping_custom_field] =>
[42] =>
[shipping_method] =>
[43] =>
[shipping_code] =>
[44] => 1,19
[comment] => 1,19
[45] => 100.0000
[total] => 100.0000
[46] => 0
[order_status_id] => 0
[47] => 0
[affiliate_id] => 0
[48] => 0.0000
[commission] => 0.0000
[49] => 0
[marketing_id] => 0
[50] =>
[tracking] =>
[51] => 0
[language_id] => 0
[52] => 0
[currency_id] => 0
[53] => INR
[currency_code] => INR
[54] => 1.00000000
[currency_value] => 1.00000000
[55] =>
[ip] =>
[56] =>
[forwarded_ip] =>
[57] =>
[user_agent] =>
[58] =>
[accept_language] =>
[59] => 0000-00-00 00:00:00
[date_added] => 0000-00-00 00:00:00
[60] => 0000-00-00 00:00:00
[date_modified] => 0000-00-00 00:00:00
)
but when i am trying to print the value of echo $mysqlw['telephone']; it is throwing warning Warning: Illegal string offset 'telephone' in
What mistake I am making in this code ?
You are trying to do a foreach on the array that you've displayed in your post. That means you're cycling through each item in the array. By trying to access $mysqlw['telephone'] you're expecting the item in the array to be another array containing the key 'telephone'.
I believe you're intending to do this:
while ($mysqlw = mysqli_fetch_array($mysqlq) {
echo $mysqlw['telephone'];
}
But also, you really should read up on how to do MySQL in a more modern style. Using things like mysqli_query in the manner you've used it here can open you up to injection attacks when you start having user input involved in the query.
Note your foreach statement has same variable name on both sides of 'as'
foreach($mysqlw as $mysqlw)
If you want to loop and access each value of an array do this instead:
foreach($mysqlw as $value)
{
echo $value;
}

Remove consecutive occurrences of string "start" from array PHP ARRAY

I have the following array
Array ( [0] => **start** [1] => **start** [2] => name [3] => producer [4] => contact name [5] => 03354222271 [6] => fzahid001#gmail.com [7] => day contact name [8] => 03354222271 [9] => venue name [10] => adress [11] => country [12] => city [13] => desc [14] => file [15] => 2016-01-01 [16] => 01:00 [17] => 06:00 [18] => 2 [19] => music_festival [20] => 2000+ [21] => quick [22] => alcohol [23] => quick [24] => 10x10 [25] => ***no*** [26] => ***no*** [27] => ***no*** [28] => 2 [29] => 0 [30] => 4 [31] => $158 [32] => $118.5 [33] => $284 [34] => $960 [35] => **start** [36] => na [37] => producer [38] => con [39] => 1 [40] => fzahid001#gmail.com [41] => nam [42] => 1 [43] => venue [44] => ad [45] => co [46] => ci [47] => description test [48] => download555ssss.png [49] => 2016-12-07 [50] => 13:00 [51] => 19:00 [52] => 2 [53] => manual_selection [54] => ATV [55] => 10x10 [56] => no [57] => no [58] => no [59] => 1 [60] => 1 [61] => 1 [62] => $109.5 [63] => $118.5 [64] => $99.5 [65] => $728 [66] => **start** [67] => Race [68] => Race Club [69] => Faizan [70] => 03354222271 [71] => fzahid001#gmail.com [72] => Faizan Zahid [73] => 03354222271 [74] => DHA [75] => 90-H Tariq Gardens [76] => Pakistan [77] => Lahore [78] => [79] => images.jpg [80] => 2017-01-01 [81] => 00:00 [82] => 07:00 [83] => 2 [84] => cycling_road_race [85] => 1_field [86] => 1_399 [87] => electronic [88] => quick [89] => 10x10 [90] => no [91] => no [92] => no [93] => 1 [94] => 0 [95] => 1 [96] => $109.5 [97] => $118.5 [98] => $99.5 [99] => $796.5 [100] => )
Now what I want to do is, remove the consecutive duplicates of "start". I am currently using following code
foreach ($updateddata as $value){
if($value != $previousvalue){
array_push($finaldata, $value);
}
$previousvalue = $value;
}
but is also removes other consecutive duplicates as well which I don't want to remove. Kindly help me how to do this.
I have highlighted the occurrences of "start" which I want to remove and make it one single entry, while leaving the other string as it is e.g. I don't want to remove the duplicates of string "no"
Try this
if($value != $previousvalue){
array_push($finaldata, $value);
} else if( $value != 'start'){
array_push($finaldata, $value);
}
To remove the consecutive duplicates of "start" value you should restrict the crucial condition to that value. Use the following approach:
// exemplary array
$updateddata = [
'start', 'start', 'producer', 'contact', 'no', 'no'
];
foreach ($updateddata as $k => $v) {
if (isset($updateddata[$k-1]) && $v == 'start' && $v == $updateddata[$k-1]) {
unset($updateddata[$k]);
}
}
The output:
Array
(
[0] => start
[2] => producer
[3] => contact
[4] => no
[5] => no
)

split big array into multiple arrays where empty element occurs in php

This is Input:-print_r($result4);
Output:-Array ( [0] => A-I-only [1] => B-III-only [2] => C-I-and-II-only [3]=> D-II-and-III-only [4] => E-I,-II,-III [5] => [6] => A-Hepatitis-A [7] => B-Hepatitis-B [8] => C-Hepatitis-C [9] => D-Hepatitis-B-and-C [10] => E-None-of-the-above [11] => [12] => A)-Cholestasis [13] => B)-Cholecystitis [14] => C)-Cholelithiasis [15] => D)-Hepatic-encephalopathy [16] => E)-Ascites [17] => [18] => A-Acetyl-salicylic-acid [19] => B-Ibuprofen [20] => C-Acetaminophen [21] => D-Pepto-Bismol [22] => E-All-of-the-above [23] => [24] => [25] => A-dark-urine [26] => B-stomach-pain [27] => C-blood-in-stools [28] => D-yellowing-of-skin [29] => E-Yellowing-of-eye-and-mucus [30] => [31] => A-Hepatitis-A [32] => B-Hepatitis-B [33] => C-Dukoral [34] => D-Gerdasil [35] => E-None-of-the-above [36] => [37] => cervical-cancer-caused-by-papilloma-virus [38] => A-Glucuronidation [39] => B-Glutathione-conjugation [40] => C-Acetylation [41] => D-Sulfate-conjugation [42] => E-Methylation [43] => [44] => A-Acetylcysteine [45] => B-cysteine [46] => C-Mercapturic-acid [47] => D-Glutathione-conjugation [48] => E-Glutathione-only [49] => [50] => administered-in-teenagers-to-prevent-cervical-cancer. [51] => A-Hepatitis-A [52] => B-Hepatitis-C [53] => C-Hepatitis-D [54] => D-Hepatitis-A,-B-&-C [55] => E-Hepatitis-A,-B-&-D [56] => [57] => [58] => A)-ALT [59] => B)-AST [60] => C)-Bilirubin- [61] => D)-Albumin [62] => E)-Proteins [63] => [64] => A--Saliva- [65] => B-Bile- [66] => C-Pancreatic-duct---- [67] => D-Gastric-secretions [68] => [69] => A)-Sexual-contact [70] => B)-Blood-transfusion [71] => C-Food-and-drink-contamination [72] => D-Traveling-abroad [73] => E-Drugs [74] => [75] => A)-Hepatitis-A-only [76] => B)-Hepatitis-B-only [77] => C)-Hepatitis-A-and-B [78] => D)-Hepatitis-A,-B-and-C [79] => E)-Hepatitis-B-and-C [80] => [81] => [82] => A)-Proton-pump-inhibitors [83] => B)-Warfarin [84] => C)-antacids [85] => D)Lipid-soluble-drugs [86] => E)-Parenteral-drugs [87] => [88] => A)-spironolactone- [89] => B)-NSAIDs- [90] => C)-acetaminophen- [91] => D)-Ibuprofen- [92] => E)-codeine [93] => [94] => A)-constipation- [95] => B)-ascites- [96] => C)-encephalitis- [97] => D)-liver-cirrhosis- [98] => E)-Hepatitis [99] => [100] => encephalitis. [101] => contaminated-hepatitis? [102] => A)-Hepatitis-A [103] => B)-Hepatitis-B [104] => C)-Hepatitis-A-and-B [105] => D)-Hepatitis-C [106] => E)-Hepatitis-D [107] => [108] => A)-Hepatitis-A [109] => [110] => B)-Hepatitis-A-and-B [111] => C)-Hepatitis-B-and-C [112] => D)-Hepatitis-A,-B,-C [113] => [114] => [115] => )
now i want to split array into multiple arrays where empty element occurs like
Array ( [0] => A-I-only [1] => B-III-only [2] => C-I-and-II-only [3]=> D-II-and-III-only [4] => E-I,-II,-III ) Array([6] => A-Hepatitis-A [7] => B-Hepatitis-B [8] => C-Hepatitis-C [9] => D-Hepatitis-B-and-C [10] => E-None-of-the-above )....similarly
Below will work,
$new_array = array();
$i = 0;
foreach($array as $k => $v)
{
if (!empty($v))
{
$new_array[$i][$k] = $v;
continue;
}
$i++;
}
//This will fix your missing fourth index<br/>
$new_array = array_values($new_array);
var_dump($new_array);
DEMO.

Only show content of 1 array by it's name

If have and array like this:
Array (
[Example1] => Array
(
[0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] =>
)
[Example2] => Array
(
[0] => [1] => [2] => [3] => [4] =>
[5] => [6] => [7] => [8] => [9] =>
[10] => [11] => [12] => [13] => [14] =>
[15] => [16] => [17] => [18] => [19] =>
[20] => [21] => [22] => [23] => [24] =>
[25] => [26] => [27] => [28] => [29] =>
[30] => [31] => [32] => [33] => [34] =>
[35] => [36] => [37] => [38] => [39] =>
[40] => [41] => [42] => [43] => [44] =>
[45] => [46] => [47] => [48] => [49] =>
[50] => [51] => [52] => [53] => [54] =>
[55] => [56] => [57] => [58] => [59] =>
[60] => [61] => [62] => [63] => [64] =>
[65] => [66] => [67] => [68] => [69] =>
[70] => [71] => [72] => [73] => [74] =>
[75] => [76] => [77] => [78] => [79] =>
[80] => [81] => [82] => [83] => [84] =>
[85] => [86] => [87] => [88] => [89] =>
[90] => [91] => [92] => [93] => [94] =>
[95] => [96] => [97] => [98] => [99] =>
[100] => [101] => [102] => [103] => [104] =>
[105] => [106] => [107] => [108] => [109] =>
[110] => [111] => [112] => [113] => [114] =>
[115] => [116] => [117] => [118] => [119] =>
[120] => [121] => [122] => [123] => [124] =>
[125] => [126] => [127] => [128] => [129] =>
[130] => [131] => [132] => [133] => [134] =>
)
)
There's is 2 primary arrays (Example1 & Example2) and in those another array is made. I would like to know how I can only call only 1 array like "Example2" so it print only that one and ignore "Example1"
Please note that there could be more than 2 primary arrays.
And what if with that array I want to build a drop down menu, here what I have:
$__selectGroups = '';
foreach ($groups as $key => $options)
{
sort($options);
if ($key !== '')
{
$__selectGroups .= '<optgroup label="'.$key.'">';
}
$__selectGroups .= implode("\n", $options);
if ($key !== '')
{
$__selectGroups .= '</optgroup>';
}
}
How can I tell to build the drop down with only Example2 and ignore the others?
I'm not sure I understand the question... seems too simple:
print_r($yourArray['Example1']);
Since you edited your question, I think you want to do this?
foreach ($yourArray['Example1'] as $key => $value) {
}
This paradigm for accessing nested arrays applies across the board...
You need something like this:
echo '<pre>';
print_r($yourArray['Example1']);
print_r($yourArray['Example2']);
echo '<pre>';
Or you need something more elaborated?

Categories