i am working on a custom Google Analytics implementation making use of direct utm.gif requests.
The problem:
Google Analytics doesnt track any data. Maybe because sth. is wrong with the parameters?
Thank's for helping
Sample: trackPage parameters
array(16) {
[0]=>
string(53) "http://www.google-analytics.com/__utm.gif?utmwv=4.5.7"
[1]=>
string(14) "utmn=474288553"
[2]=>
string(34) "utmhn=labs.domain.de%2Fphp%2Fga%2F"
[3]=>
string(16) "utmcs=ISO-8859-1"
[4]=>
string(11) "utmul=de-de"
[5]=>
string(7) "utmsr=-"
[6]=>
string(7) "utmsc=-"
[7]=>
string(7) "utmje=-"
[8]=>
string(7) "utmfl=-"
[9]=>
string(6) "utmr=-"
[10]=>
string(70) "utme=8%28userstatus%2Amyvariable%299%28nofan%2Amyvalue%2911%281%2A1%29"
[11]=>
string(14) "utmdt=Homepage"
[12]=>
string(16) "utmhid=441842675"
[13]=>
string(12) "utmp=home%2F"
[14]=>
string(17) "utmac=UA-123456-1"
[15]=>
string(191) "utmcc=__utma%253D186215409.1789216404.1265552708.1288611723.1288619999.26%253B%252B__utmz%253D186215409.1288619999.1.1.utmcsr%3D%28direct%29%7Cutmccn%3D%28direct%29%7Cutmcmd%3D%28none%29%253B"
}
Sample: trackEvent parameters
array(15) {
[0]=>
string(53) "http://www.google-analytics.com/__utm.gif?utmwv=4.5.7"
[1]=>
string(14) "utmn=240340321"
[2]=>
string(34) "utmhn=labs.domain.de%2Fphp%2Fga%2F"
[3]=>
string(10) "utmt=event"
[4]=>
string(16) "utmcs=ISO-8859-1"
[5]=>
string(11) "utmul=de-de"
[6]=>
string(7) "utmsr=-"
[7]=>
string(7) "utmsc=-"
[8]=>
string(7) "utmje=-"
[9]=>
string(7) "utmfl=-"
[10]=>
string(6) "utmr=-"
[11]=>
string(116) "utme=5%28permission%2Apublish_stream%2Agranted%29%281%298%28userstatus%2Amyvariable%299%28%2Amyvalue%2911%281%2A1%29"
[12]=>
string(16) "utmhid=364249414"
[13]=>
string(17) "utmac=UA-123456-1"
[14]=>
string(191) "utmcc=__utma%253D186215409.1789216404.1265552708.1288611723.1288620331.26%253B%252B__utmz%253D186215409.1288620331.1.1.utmcsr%3D%28direct%29%7Cutmccn%3D%28direct%29%7Cutmcmd%3D%28none%29%253B"
}
This one is generated with another lib and it's working. But i can't find my fault?
array(14) {
[0]=>
string(53) "http://www.google-analytics.com/__utm.gif?utmwv=4.5.7"
[1]=>
string(15) "utmn=8893029624"
[2]=>
string(18) "utmhn=labs.domain.de%2Fphp%2Fga%2F"
[3]=>
string(7) "utmcs=-"
[4]=>
string(7) "utmsr=-"
[5]=>
string(7) "utmsc=-"
[6]=>
string(11) "utmul=de-de"
[7]=>
string(7) "utmje=-"
[8]=>
string(7) "utmfl=-"
[9]=>
string(14) "utmdt=Homepage"
[10]=>
string(6) "utmr=-"
[11]=>
string(10) "utmp=/home"
[12]=>
string(17) "utmac=UA-123456-1"
[13]=>
string(199) "utmcc=__utma%3D155417661.238248693.1267644354.1279870281.1279921084.8%3B%2B__utmz%3D155417661.1279824753.5.6.utmccn=(organic)%7Cutmcsr=google%7Cutmctr=facebook%20goole%20analytics%7Cutmcmd=organic%3B"
}
Related
i returned a array off all my admin submenu items. but this returns like this:
array(2) { [0]=> string(4) "read" [10]=> string(11) "update_core" } array(0) { } array(4) { [5]=> string(10) "edit_posts" [10]=> string(10) "edit_posts" [15]=> string(17) "manage_categories" [16]=> string(16) "manage_post_tags" } array(3) { [5]=> string(12) "upload_files" [10]=> string(12) "upload_files" [15]=> string(17) "manage_categories" } array(2) { [5]=> string(10) "edit_pages" [10]=> string(10) "edit_pages" } array(0) { } array(4) { [5]=> string(10) "edit_posts" [10]=> string(10) "edit_posts" [15]=> string(17) "manage_categories" [16]=> string(17) "manage_categories" } array(3) { [5]=> string(10) "edit_posts" [10]=> string(10) "edit_posts" [15]=> string(17) "manage_categories" } array(0) { } array(8) { [0]=> string(18) "edit_theme_options" [1]=> string(19) "edit_us_page_blocks" [2]=> string(19) "edit_us_page_blocks" [3]=> string(19) "edit_us_page_blocks" [4]=> string(19) "edit_us_page_blocks" [5]=> string(14) "manage_options" [6]=> string(14) "manage_options" [7]=> string(14) "manage_options" } array(4) { [5]=> string(13) "switch_themes" [6]=> string(9) "customize" [7]=> string(18) "edit_theme_options" [10]=> string(18) "edit_theme_options" } array(2) { [5]=> string(16) "activate_plugins" [10]=> string(15) "install_plugins" } array(3) { [5]=> string(10) "list_users" [10]=> string(12) "create_users" [15]=> string(4) "read" } array(7) { [5]=> string(10) "edit_posts" [10]=> string(6) "import" [15]=> string(6) "export" [20]=> string(23) "view_site_health_checks" [25]=> string(27) "export_others_personal_data" [30]=> string(26) "erase_others_personal_data" [50]=> string(13) "setup_network" } array(5) { [0]=> string(14) "manage_options" [1]=> string(14) "manage_options" [2]=> string(14) "manage_options" [3]=> string(14) "manage_options" [5]=> string(10) "edit_posts" } array(7) { [10]=> string(14) "manage_options" [15]=> string(14) "manage_options" [20]=> string(14) "manage_options" [25]=> string(14) "manage_options" [30]=> string(14) "manage_options" [40]=> string(14) "manage_options" [45]=> string(22) "manage_privacy_options" } array(3) { [0]=> string(14) "manage_options" [1]=> string(14) "manage_options" [2]=> string(14) "manage_options" } array(0) { } array(0) { } array(2) { [0]=> string(14) "manage_options" [1]=> string(4) "read" }
php code:
$subMenuItems = wp_list_pluck($submenu_list, 1);
var_dump($subMenuItems);
i know this array is long, is it me or is this broken
i hope that someone can explain why the array items are not like [0] => .... [1] => .... but random
According to the documentation:
wp_list_pluck( array $list, int|string $field, int|string $index_key = null ): array
Array of found values. If $index_key is set, an array of found values with keys corresponding to $index_key. If $index_key is null, array keys from the original $list will be preserved in the results.
You need to add a third parameter, if you want to conserve indexed keys order.
Regards,
while developing Laravel app I stuck on one problem with array sorting. At the beginning, I used partition problem to split my array into equal chunks by time, but now I have a problem sorting by the id of the array.
My array:
array(2) {
[0]=>
array(3) {
[0]=>
array(8) {
[0]=>
int(4) <----- this is value i need to sort by
[1]=>
int(15)
[2]=>
string(64) "text..."
[3]=>
string(6) "650008"
[4]=>
string(13) "NP08KDT"
[5]=>
int(48)
[6]=>
string(6) "456467"
[7]=>
int(33)
}
[1]=>
array(8) {
[0]=>
int(6)
[1]=>
int(10)
[2]=>
string(64) "text..."
[3]=>
string(6) "650008"
[4]=>
string(13) "NP08KDT"
[5]=>
int(48)
[6]=>
string(6) "456467"
[7]=>
int(33)
}
[2]=>
array(8) {
[0]=>
int(2)
[1]=>
int(8)
[2]=>
string(85) "text..."
[3]=>
string(6) "650008"
[4]=>
string(13) "NP08KDT"
[5]=>
int(48)
[6]=>
string(6) "456467"
[7]=>
int(33)
}
}
[1]=>
array(3) {
[0]=>
array(8) {
[0]=>
int(3)
[1]=>
int(14)
[2]=>
string(158) "text..."
[3]=>
string(6) "650008"
[4]=>
string(13) "NP08KDT"
[5]=>
int(48)
[6]=>
string(6) "456467"
[7]=>
int(33)
}
[1]=>
array(8) {
[0]=>
int(5)
[1]=>
int(12)
[2]=>
string(158) "text..."
[3]=>
string(6) "650008"
[4]=>
string(13) "NP08KDT"
[5]=>
int(48)
[6]=>
string(6) "456467"
[7]=>
int(33)
}
[2]=>
array(8) {
[0]=>
int(1)
[1]=>
int(7)
[2]=>
string(55) "text..."
[3]=>
string(6) "650008"
[4]=>
string(13) "NP08KDT"
[5]=>
int(48)
[6]=>
string(6) "456467"
[7]=>
int(33)
}
}
}
I need to sort by the first value of each array, so called my id.
Output I need:
array(2) {
[0]=>
array(3) {
[0]=>
array(8) {
[0]=>
int(1)
[1]=>
int(15)
[2]=>
string(64) "text..."
[3]=>
string(6) "650008"
[4]=>
string(13) "NP08KDT"
[5]=>
int(48)
[6]=>
string(6) "456467"
[7]=>
int(33)
}
[1]=>
array(8) {
[0]=>
int(2)
[1]=>
int(10)
[2]=>
string(64) "text..."
[3]=>
string(6) "650008"
[4]=>
string(13) "NP08KDT"
[5]=>
int(48)
[6]=>
string(6) "456467"
[7]=>
int(33)
}
[2]=>
array(8) {
[0]=>
int(3)
[1]=>
int(8)
[2]=>
string(85) "text..."
[3]=>
string(6) "650008"
[4]=>
string(13) "NP08KDT"
[5]=>
int(48)
[6]=>
string(6) "456467"
[7]=>
int(33)
}
}
[1]=>
array(3) {
[0]=>
array(8) {
[0]=>
int(4)
[1]=>
int(14)
[2]=>
string(158) "text..."
[3]=>
string(6) "650008"
[4]=>
string(13) "NP08KDT"
[5]=>
int(48)
[6]=>
string(6) "456467"
[7]=>
int(33)
}
[1]=>
array(8) {
[0]=>
int(5)
[1]=>
int(12)
[2]=>
string(158) "text..."
[3]=>
string(6) "650008"
[4]=>
string(13) "NP08KDT"
[5]=>
int(48)
[6]=>
string(6) "456467"
[7]=>
int(33)
}
[2]=>
array(8) {
[0]=>
int(6)
[1]=>
int(7)
[2]=>
string(55) "text..."
[3]=>
string(6) "650008"
[4]=>
string(13) "NP08KDT"
[5]=>
int(48)
[6]=>
string(6) "456467"
[7]=>
int(33)
}
}
}
maybe any of you guys have any solutions how i could solve this problem, so far i tried a lot of sorting functions, none of them seems to work properly for me.
Thank you!
this may not be the best way to do this, but you can try something like this.
$tempArray = array();
$sortedArray = array();
foreach ($yourArray as $key1 => $arr){// create 2D array
foreach ($arr as $key2 => $arr2){
$tempArray[] = $arr2;
}
}
foreach ($tempArray as $keyTemp => $tempElem){
$sortingArray[] = $tempElem[0];//get array value you need to sort
}
asort($sortingArray);// sort array maintaining the key
foreach ($sortingArray as $keySort => $sortElem){//loop through sorted array to push elements to a new array
$sortedArray[] = $tempArray[$keySort];
}
print_r($sortedArray);
After I use array_unique on an array, when I var_dump the array, it still has the same content, with duplicates:
array(21) {
[0]=> string(10) "tricou_CRS"
[1]=> string(10) "tricou_CRM"
[2]=> string(11) "tricou_CRXL"
[3]=> string(10) "tricou_CBM"
[4]=> string(10) "tricou_CBL"
[5]=> string(10) "tricou_CWS"
[6]=> string(11) "tricou_CWXL"
[7]=> string(10) "tricou_CRS"
[8]=> string(10) "tricou_CRM"
[9]=> string(11) "tricou_CRXL"
[10]=> string(10) "tricou_CBM"
[11]=> string(10) "tricou_CBL"
[12]=> string(10) "tricou_CWS"
[13]=> string(11) "tricou_CWXL"
[14]=> string(10) "tricou_CRS"
[15]=> string(10) "tricou_CRM"
[16]=> string(11) "tricou_CRXL"
[17]=> string(10) "tricou_CBM"
[18]=> string(10) "tricou_CBL"
[19]=> string(10) "tricou_CWS"
[20]=> string(11) "tricou_CWXL" }
Which obviously has some duplicates. Now, there's not much code that could help, really, because it's just array_unique($myarr);var_dump($myarr);.
So, what am I missing there? Shouldn't array_unique remove the duplicates? Both the type and the content is the same in many of the array's positions.
$uniquearr = array_unique($myarr);
var_dump($uniquearr);
Always read docs first
http://www.php.net/array_unique
array_unique
Return Values
Returns the filtered array.
Here is a sample var_dump. Now, how do I know how to construct a foreach from it to load any particular word or fragment in to an array?
object(stdClass)#1 (2)
{
["noun"]=>
object(stdClass)#2 (1)
{
["syn"]=> array(24)
{
[0]=> string(12) "domestic dog"
[1]=> string(16) "Canis familiaris"
[2]=> string(5) "frump"
[3]=> string(3) "cad"
[4]=> string(7) "bounder"
[5]=> string(10) "blackguard"
[6]=> string(5) "hound"
[7]=> string(4) "heel"
[8]=> string(5) "frank"
[9]=> string(11) "frankfurter"
[10]=> string(6) "hotdog"
[11]=> string(7) "hot dog"
[12]=> string(6) "wiener"
[13]=> string(11) "wienerwurst"
[14]=> string(6) "weenie"
[15]=> string(4) "pawl"
[16]=> string(6) "detent"
[17]=> string(5) "click"
[18]=> string(7) "andiron"
[19]=> string(7) "firedog"
[20]=> string(8) "dog-iron"
[21]=> string(8) "blighter"
[22]=> string(5) "canid"
[23]=> string(6) "canine"
[24]=> string(5) "catch"
}
}
}
Before we can decipher it, we have to format it.
Tobias Kun's answer shows a very good way to format the var_dump output so you can read it.
object(stdClass)#1 (2)
{
["noun"]=>
object(stdClass)#2 (1)
{
["syn"]=> array(24)
{
[0]=> string(12) "domestic dog"
[1]=> string(16) "Canis familiaris"
[2]=> string(5) "frump"
[3]=> string(3) "cad"
[4]=> string(7) "bounder"
[5]=> string(10) "blackguard"
[6]=> string(5) "hound"
[7]=> string(4) "heel"
[8]=> string(5) "frank"
[9]=> string(11) "frankfurter"
[10]=> string(6) "hotdog"
[11]=> string(7) "hot dog"
[12]=> string(6) "wiener"
[13]=> string(11) "wienerwurst"
[14]=> string(6) "weenie"
[15]=> string(4) "pawl"
[16]=> string(6) "detent"
[17]=> string(5) "click"
[18]=> string(7) "andiron"
[19]=> string(7) "firedog"
[20]=> string(8) "dog-iron"
[21]=> string(8) "blighter"
[22]=> string(5) "canid"
[23]=> string(6) "canine"
[24]=> string(5) "catch"
}
}
}
You have a stdClass object with a property called ,"noun". noun is an abject with a property called "syn", which is an array of strings.
Suppose we call the object $object. Then we can access the array like:
echo $object->noun->syn[23];
which gives us canine. So a loop might look like:
foreach($data->noun->syn as $value) {
echo $value . "<br>\n";
}
First of all you should really increase the quality of your questions. The code is not formatted at all.
If you use echo "<pre>" . print_r($your_data_object_or_array,1) . "</pre>" your data will be formatted fine.
If i understand you right this should help you:
foreach($data['noun']['syn'] as $value) {
//with this you loop through all your words in "syn" e.g. domestic, "Canis familiaris etc."
echo $value . "<br>";
}
//Ouput:
domestic
Canis familiaris
frump
cad
etc ...
This question already has answers here:
How can I merge multiple separate arrays that are not included in an array? [duplicate]
(2 answers)
Closed 9 years ago.
Ok , so I have a $unique_answer_title contains multiple arrays. Below is what I get when I use var_dump($unique_answer_title):
array(4) { [0]=> string(9) "Immediate" [1]=> string(3) "Yes" [2]=> string(29) "Have a representative call me" [3]=> string(109) "Biomek<sup><em></em></sup> FX<sup>P</sup> Workstation" } array(8) { [0]=> string(9) "Immediate" [1]=> string(3) "Yes" [2]=> string(29) "Have a representative call me" [3]=> string(109) "Biomek<sup><em></em></sup> FX<sup>P</sup> Workstation" [4]=> string(9) "Immediate" [5]=> string(2) "No" [6]=> string(29) "Have a representative call me" [7]=> string(111) "Biomek<sup><em></em></sup> NX<sup>P</sup> Workstation " } array(12) { [0]=> string(9) "Immediate" [1]=> string(3) "Yes" [2]=> string(29) "Have a representative call me" [3]=> string(109) "Biomek<sup><em></em></sup> FX<sup>P</sup> Workstation" [4]=> string(9) "Immediate" [5]=> string(2) "No" [6]=> string(29) "Have a representative call me" [7]=> string(111) "Biomek<sup><em></em></sup> NX<sup>P</sup> Workstation " [8]=> string(20) "Greater than 3 years" [9]=> string(3) "Yes" [10]=> string(42) "Have a representative contact me via email" [11]=> string(109) "Biomek<sup><em></em></sup> FX<sup>P</sup> Workstation" } array(18) { [0]=> string(9) "Immediate" [1]=> string(3) "Yes" [2]=> string(29) "Have a representative call me" [3]=> string(109) "Biomek<sup><em></em></sup> FX<sup>P</sup> Workstation" [4]=> string(9) "Immediate" [5]=> string(2) "No" [6]=> string(29) "Have a representative call me" [7]=> string(111) "Biomek<sup><em></em></sup> NX<sup>P</sup> Workstation " [8]=> string(20) "Greater than 3 years" [9]=> string(3) "Yes" [10]=> string(42) "Have a representative contact me via email" [11]=> string(109) "Biomek<sup><em></em></sup> FX<sup>P</sup> Workstation" [12]=> string(9) "Immediate" [13]=> string(2) "No" [14]=> string(15) "Send literature" [15]=> string(77) "Sign me up for more info on the Biomek 4000<sup></sup>." [16]=> string(88) "Biomek<sup><em></em></sup> Assay Workstation" [17]=> string(72) "SPRIworks Library Construction <sup>^^</sup>" } array(22) { [0]=> string(9) "Immediate" [1]=> string(3) "Yes" [2]=> string(29) "Have a representative call me" [3]=> string(109) "Biomek<sup><em></em></sup> FX<sup>P</sup> Workstation" [4]=> string(9) "Immediate" [5]=> string(2) "No" [6]=> string(29) "Have a representative call me" [7]=> string(111) "Biomek<sup><em></em></sup> NX<sup>P</sup> Workstation " [8]=> string(20) "Greater than 3 years" [9]=> string(3) "Yes" [10]=> string(42) "Have a representative contact me via email" [11]=> string(109) "Biomek<sup><em></em></sup> FX<sup>P</sup> Workstation" [12]=> string(9) "Immediate" [13]=> string(2) "No" [14]=> string(15) "Send literature" [15]=> string(77) "Sign me up for more info on the Biomek 4000<sup></sup>." [16]=> string(88) "Biomek<sup><em></em></sup> Assay Workstation" [17]=> string(72) "SPRIworks Library Construction <sup>^^</sup>" [18]=> string(9) "Immediate" [19]=> string(2) "No" [20]=> string(30) "Have a representative visit me" [21]=> string(77) "Sign me up for more info on the Biomek 4000<sup></sup>." } array(26) { [0]=> string(9) "Immediate" [1]=> string(3) "Yes" [2]=> string(29) "Have a representative call me" [3]=> string(109) "Biomek<sup><em></em></sup> FX<sup>P</sup> Workstation" [4]=> string(9) "Immediate" [5]=> string(2) "No" [6]=> string(29) "Have a representative call me" [7]=> string(111) "Biomek<sup><em></em></sup> NX<sup>P</sup> Workstation " [8]=> string(20) "Greater than 3 years" [9]=> string(3) "Yes" [10]=> string(42) "Have a representative contact me via email" [11]=> string(109) "Biomek<sup><em></em></sup> FX<sup>P</sup> Workstation" [12]=> string(9) "Immediate" [13]=> string(2) "No" [14]=> string(15) "Send literature" [15]=> string(77) "Sign me up for more info on the Biomek 4000<sup></sup>." [16]=> string(88) "Biomek<sup><em></em></sup> Assay Workstation" [17]=> string(72) "SPRIworks Library Construction <sup>^^</sup>" [18]=> string(9) "Immediate" [19]=> string(2) "No" [20]=> string(30) "Have a representative visit me" [21]=> string(77) "Sign me up for more info on the Biomek 4000<sup></sup>." [22]=> string(9) "Immediate" [23]=> string(2) "No" [24]=> string(5) "Other" [25]=> string(88) "Biomek<sup><em></em></sup> Assay Workstation" }
How can I combine all the elements of these arrays shown below into one numerical array?
array_merge($unique_answer_title) doesn't seem to work ... and the variable $unique_answer_title itself is not an array, it's a group of multiple arrays. How can I get the elements of all these individual arrays together into one big array?
You need to merge the single arrays in a foreach loop.
$mergedArray = array();
foreach($unique_answer_title as $single){
$mergedArray = array_merge($mergedArray, $single);
}