How can I insert an associative array into sql? - php
This is my array:
[abominado] => Array
(
[0] => réprobo
[1] => réprobo
[2] => abominado
[3] => banido
[4] => condenado
[5] => detestado
[6] => odiado
[7] => precito
[8] => renegado
[9] => repudiado
)
[abominar] => Array
(
[0] => repelir
[1] => repelir
[2] => abominar
[3] => afastar
[4] => afugentar
[5] => arredar
[6] => desalojar
[7] => desviar
[8] => detestar
[9] => empuxar
[10] => escorraçar
[11] => espinafrar
[12] => execrar
[13] => exercer
[14] => expulsar
[15] => grimpar
[16] => impugnar
[17] => odiar
[18] => rebater
[19] => rechaçar
[20] => recusar
[21] => rejeitar
[22] => relegar
[23] => repudiar
)
how can I insert it into sql ?
foreach ($abominado as $key=>$str)
{
$string .= "$key:$str\n";
}
mysql_query("INSERT INTO strings VALUES ('".mysql_real_escape_string($string)."')");
You can use serialize to cast it to string and unserialize when you get it
First, these arrays happen to be sequential.
Second, in a SQL table, any column can be used as a search criteria, so just insert the data directly and set up an index on any searchable column.
Related
How to find and store in PHP array all the hours found inside of an SQL database `Datetime` column seperated by day?
First of all, I am using this piece of code in PHP to retrieve data from a database. DATABASE DATA CODE: // Database Details $servername = "localhost"; $username = "admin_testdb"; $password = "123412345"; $dbname = "test_db"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM `HOURLY_DATA` WHERE 1 ORDER BY `HOURLY_DATA`.`TIME` ASC"; // Run $sql content as sql script in db. $result=$conn->query($sql); This code is just fine and has absolutely no errors or problems related to my goal here. Also the specific data table I am looking after in this Query is the table named TIME which is of type "Datetime" format in SQL which looks like this: DATETIME FORMAT: YYYY-MM-DDTHH:MM:SS or to make it more clear an example would be 1970-09-24T05:00:00 Now moving onto what I am trying to achieve, my code and then the problem. The Goal: I have a list of data in the datetime format explained above, where theres HOURS missing, the increment of the HOURS is always +1 meaning that an example of missing data inside this data table would be: 2021-11-01T00:00:00 2021-11-01T01:00:00 2021-11-01T02:00:00 2021-11-01T05:00:00 2021-11-01T06:00:00 2021-11-01T07:00:00 2021-11-01T08:00:00 2021-11-01T13:00:00 2021-11-01T14:00:00 2021-11-01T15:00:00 2021-11-01T16:00:00 2021-11-01T17:00:00 2021-11-01T18:00:00 2021-11-01T19:00:00 2021-11-01T20:00:00 2021-11-01T21:00:00 So by taking a look at this DATETIME list above, we can understand that there is data missing and more specifically hours missing like 22:00:00 or 23:00:00 etc... Now I want to write a code that will find this missing HOUR steps. So far I have tried this code: // Run $sql content as sql script in db. $result=$conn->query($sql); $flag = 0; $i = 0; $x = 0; $cont = array(); $temp = array(); foreach ($result as $value) { $singular_value = $value["TIME"]; $singular_value = str_replace(" ", "", $singular_value); $day_value = $singular_value[8].$singular_value[9]; $day_value = (int) $day_value; $singular_value = $singular_value[11].$singular_value[12]; $singular_value = (int) $singular_value; // First time running. if ( $flag == 0 ){ $day_chair = $day_value; $flag = 1; } if ( $day_chair == $day_value ){ $temp[]= $value["TIME"]; $cont[$i]= $temp; $day_chair = $day_value; } else { if ( $day_value == 30 || $day_value == 31 ){ $day_chair = 1; continue; } else { $day_chair += 1; $temp = array(); } $i++; } } print("<pre>".print_r($cont,true)."</pre>"); *PROBLEM: To begin with this code returns the hour 00 which is considered to be the 12 o'clock midnight only for the first iteration or day. Also the code above is supposed to return and array that will look like this: Array ( [0] => Array ( [0] => 2021-11-01T00:00:00 [1] => 2021-11-01T01:00:00 [2] => 2021-11-01T02:00:00 [3] => 2021-11-01T03:00:00 [4] => 2021-11-01T04:00:00 [5] => 2021-11-01T05:00:00 [6] => 2021-11-01T06:00:00 [7] => 2021-11-01T07:00:00 [8] => 2021-11-01T08:00:00 [9] => 2021-11-01T09:00:00 [10] => 2021-11-01T10:00:00 [11] => 2021-11-01T11:00:00 [12] => 2021-11-01T12:00:00 [13] => 2021-11-01T13:00:00 [14] => 2021-11-01T14:00:00 [15] => 2021-11-01T15:00:00 [16] => 2021-11-01T16:00:00 [17] => 2021-11-01T17:00:00 [18] => 2021-11-01T18:00:00 [19] => 2021-11-01T19:00:00 [20] => 2021-11-01T20:00:00 [21] => 2021-11-01T21:00:00 [22] => 2021-11-01T22:00:00 [23] => 2021-11-01T23:00:00 ) [1] => Array ( [0] => 2021-11-02T00:00:00 [1] => 2021-11-02T01:00:00 [2] => 2021-11-02T02:00:00 [3] => 2021-11-02T03:00:00 [4] => 2021-11-02T04:00:00 [5] => 2021-11-02T05:00:00 [6] => 2021-11-02T06:00:00 [7] => 2021-11-02T07:00:00 [8] => 2021-11-02T08:00:00 [9] => 2021-11-02T09:00:00 [10] => 2021-11-02T10:00:00 [11] => 2021-11-02T11:00:00 [12] => 2021-11-02T12:00:00 [13] => 2021-11-02T13:00:00 [14] => 2021-11-02T14:00:00 [15] => 2021-11-02T15:00:00 [16] => 2021-11-02T16:00:00 [17] => 2021-11-02T17:00:00 [18] => 2021-11-02T18:00:00 [19] => 2021-11-02T19:00:00 [20] => 2021-11-02T20:00:00 [21] => 2021-11-02T21:00:00 [22] => 2021-11-02T22:00:00 [23] => 2021-11-02T23:00:00 ) [2] => Array ( [0] => 2021-11-03T00:00:00 [1] => 2021-11-03T01:00:00 [2] => 2021-11-03T02:00:00 [3] => 2021-11-03T03:00:00 [4] => 2021-11-03T04:00:00 [5] => 2021-11-03T05:00:00 [6] => 2021-11-03T06:00:00 [7] => 2021-11-03T07:00:00 [8] => 2021-11-03T08:00:00 [9] => 2021-11-03T09:00:00 [10] => 2021-11-03T10:00:00 [11] => 2021-11-03T11:00:00 [12] => 2021-11-03T12:00:00 [13] => 2021-11-03T13:00:00 [14] => 2021-11-03T14:00:00 [15] => 2021-11-03T15:00:00 [16] => 2021-11-03T16:00:00 [17] => 2021-11-03T17:00:00 [18] => 2021-11-03T18:00:00 [19] => 2021-11-03T19:00:00 [20] => 2021-11-03T20:00:00 [21] => 2021-11-03T21:00:00 [22] => 2021-11-03T22:00:00 [23] => 2021-11-03T23:00:00 ) ) And will leave a GAP or simply do write nothing in the array if the date is missing from the database. But this code return a lot of problematic arrays and just to give an example there are some here: First day was parsed fine but the second one and all the days after the first day are missing the 12 o'clock aka 00:00:00 E.X: [0] => Array ( [0] => 2021-11-01T00:00:00 [1] => 2021-11-01T01:00:00 [2] => 2021-11-01T02:00:00 [3] => 2021-11-01T03:00:00 [4] => 2021-11-01T04:00:00 [5] => 2021-11-01T05:00:00 [6] => 2021-11-01T06:00:00 [7] => 2021-11-01T07:00:00 [8] => 2021-11-01T08:00:00 [9] => 2021-11-01T09:00:00 [10] => 2021-11-01T10:00:00 [11] => 2021-11-01T11:00:00 [12] => 2021-11-01T12:00:00 [13] => 2021-11-01T13:00:00 [14] => 2021-11-01T14:00:00 [15] => 2021-11-01T15:00:00 [16] => 2021-11-01T16:00:00 [17] => 2021-11-01T17:00:00 [18] => 2021-11-01T18:00:00 [19] => 2021-11-01T19:00:00 [20] => 2021-11-01T20:00:00 [21] => 2021-11-01T21:00:00 [22] => 2021-11-01T22:00:00 [23] => 2021-11-01T23:00:00 ) [1] => Array ( [0] => 2021-11-02T01:00:00 [1] => 2021-11-02T02:00:00 [2] => 2021-11-02T03:00:00 [3] => 2021-11-02T04:00:00 [4] => 2021-11-02T05:00:00 [5] => 2021-11-02T06:00:00 [6] => 2021-11-02T07:00:00 [7] => 2021-11-02T08:00:00 [8] => 2021-11-02T09:00:00 [9] => 2021-11-02T10:00:00 [10] => 2021-11-02T11:00:00 [11] => 2021-11-02T12:00:00 [12] => 2021-11-02T13:00:00 [13] => 2021-11-02T14:00:00 [14] => 2021-11-02T15:00:00 [15] => 2021-11-02T16:00:00 [16] => 2021-11-02T17:00:00 [17] => 2021-11-02T18:00:00 [18] => 2021-11-02T19:00:00 [19] => 2021-11-02T20:00:00 [20] => 2021-11-02T21:00:00 [21] => 2021-11-02T22:00:00 [22] => 2021-11-02T23:00:00 ) Also, there are broken days for example when the day reaches day 30 or 31 of the month this happens: [28] => Array ( [0] => 2021-11-29T01:00:00 [1] => 2021-11-29T02:00:00 [2] => 2021-11-29T03:00:00 [3] => 2021-11-29T04:00:00 [4] => 2021-11-29T05:00:00 [5] => 2021-11-29T06:00:00 [6] => 2021-11-29T07:00:00 [7] => 2021-11-29T08:00:00 [8] => 2021-11-29T09:00:00 [9] => 2021-11-29T10:00:00 [10] => 2021-11-29T11:00:00 [11] => 2021-11-29T12:00:00 [12] => 2021-11-29T13:00:00 [13] => 2021-11-29T14:00:00 [14] => 2021-11-29T15:00:00 [15] => 2021-11-29T16:00:00 [16] => 2021-11-29T17:00:00 [17] => 2021-11-29T18:00:00 [18] => 2021-11-29T19:00:00 [19] => 2021-11-29T20:00:00 [20] => 2021-11-29T21:00:00 [21] => 2021-11-29T22:00:00 [22] => 2021-11-29T23:00:00 [23] => 2021-12-01T00:00:00 [24] => 2021-12-01T01:00:00 [25] => 2021-12-01T02:00:00 [26] => 2021-12-01T03:00:00 [27] => 2021-12-01T04:00:00 [28] => 2021-12-01T05:00:00 [29] => 2021-12-01T06:00:00 [30] => 2021-12-01T07:00:00 [31] => 2021-12-01T08:00:00 [32] => 2021-12-01T09:00:00 [33] => 2021-12-01T10:00:00 [34] => 2021-12-01T11:00:00 [35] => 2021-12-01T12:00:00 [36] => 2021-12-01T13:00:00 [37] => 2021-12-01T14:00:00 [38] => 2021-12-01T15:00:00 [39] => 2021-12-01T16:00:00 [40] => 2021-12-01T17:00:00 [41] => 2021-12-01T18:00:00 [42] => 2021-12-01T19:00:00 [43] => 2021-12-01T20:00:00 [44] => 2021-12-01T21:00:00 [45] => 2021-12-01T22:00:00 [46] => 2021-12-01T23:00:00 ) [29] => Array ( [0] => 2021-12-02T01:00:00 [1] => 2021-12-02T02:00:00 [2] => 2021-12-02T03:00:00 [3] => 2021-12-02T04:00:00 [4] => 2021-12-02T05:00:00 [5] => 2021-12-02T06:00:00 [6] => 2021-12-02T07:00:00 [7] => 2021-12-02T08:00:00 [8] => 2021-12-02T09:00:00 [9] => 2021-12-02T10:00:00 [10] => 2021-12-02T11:00:00 [11] => 2021-12-02T12:00:00 [12] => 2021-12-02T13:00:00 [13] => 2021-12-02T14:00:00 [14] => 2021-12-02T15:00:00 [15] => 2021-12-02T16:00:00 [16] => 2021-12-02T17:00:00 [17] => 2021-12-02T18:00:00 [18] => 2021-12-02T19:00:00 [19] => 2021-12-02T20:00:00 [20] => 2021-12-02T21:00:00 [21] => 2021-12-02T22:00:00 [22] => 2021-12-02T23:00:00 ) QUESTION: What can I do to solve this programmatic/algorithmic problem or what am I doing wrong in my code?
Alternative values should store in alternative position in array in php
When the values fetching from the mysql the values will be stored in series order in the array. But i want the values to store in the array in alternative position. Here some individual values from table course_id('1') values Array ( [0] => 15BCA01 [1] => 15BCA02 [2] => 15BCA03 [3] => 15BCA04 [4] => 15BCA05 [5] => 15BCA06 [6] => 15BCA07 [7] => 15BCA08 [8] => 15BCA09 [9] => 15BCA10 [10] => 15BCA11 ) course_id('2') values: Array ( [0] => 15MCA01 [1] => 15MCA02 [2] => 15MCA03 [3] => 15MCA04 [4] => 15MCA05 ) course_id('3') values: Array ( [0] => 15MBA01 [1] => 15MBA02 [2] => 15MBA03 [3] => 15MBA04 [4] => 15MBA05 ) course_id('4') values: Array ( [0] => 15MSC01 [1] => 15MSC02 [2] => 15MSC03 ) course_id('5') values: Array ( [0] => 15TAM01 [1] => 15TAM02 ) when i execute the mysql command select register_number from master where master_course_id in('1','2','3','4','5'); Current Output i am getting (as usual in series): Array ( [0] => 15BCA01 [1] => 15BCA02 [2] => 15BCA03 [3] => 15BCA04 [4] => 15BCA05 [5] => 15BCA06 [6] => 15BCA07 [7] => 15BCA08 [8] => 15BCA09 [9] => 15BCA10 [10] => 15BCA11 [11] => 15MCA01 [12] => 15MCA02 [13] => 15MCA03 [14] => 15MCA04 [15] => 15MCA05 [16] => 15MBA01 [17] => 15MBA02 [18] => 15MBA03 [19] => 15MBA04 [20] => 15MBA05 [21] => 15MSC01 [22] => 15MSC02 [23] => 15MSC03 [24] => 15TAM01 [25] => 15TAM02 ) Desired Output I want(alternative position): Array ( [0] => 15BCA01 [1] => 15MCA01 [2] => 15BCA02 [3] => 15MCA02 [4] => 15BCA03 [5] => 15MCA03 [6] => 15BCA04 [7] => 15MCA04 [8] => 15BCA05 [9] => 15MCA05 [10] => 15BCA06 [11] => 15MBA01 [12] => 15BCA07 [13] => 15MBA02 [14] => 15BCA08 [15] => 15MBA03 [16] => 15BCA09 [17] => 15MBA04 [18] => 15BCA10 [19] => 15MBA05 [20] => 15BCA11 [21] => 15MSC01 [22] => 15TAM01 [23] => 15MSC02 [24] => 15TAM02 [25] => 15MSC03 ) If the first value in the array from course_id ('1') means the second values should be from course_id ('2') alternatively they should add in array. If the course_id ('1') completed the next course_id('3') should start to add with current course_id ('2'). Like wise all the course_id values should add in the array alternatively. How to achieve this in php
In MySQL you need to use a user-defined variable to add ordering within the master_course_id groups. SELECT register_number FROM ( SELECT master_course_id, register_number, #position := IF(master_course_id = #prev_course, #position+1, 1) AS position, #prev_course := master_course_id FROM (SELECT * FROM master WHERE master_course_id IN ('1', '2', '3', '4', '5') ORDER BY master_course_id, register_number) AS m, CROSS JOIN (SELECT #position := 0, #prev_course := null) AS vars ) AS t ORDER BY position, master_course_id The subquery adds an extra position column that counts up sequentially within each course ID. Then the outer query reorders everything by position first, then by course ID.
Get common values from a single multidimensional array in php
I have a array called $array which is multidimensional array. It consits of keys like brandname, productsubcategory (Keys are not static they can be anything and even number of keys are not fixed). I want all the common values from the array Current array: $array = array ( [brandname] => Array ( [0] => Array ( [0] => sony_brandname [1] => touch screen_type [3] => 2.8_size [4] => gsm + gsm_sim_support [5] => 2_primary_camera [6] => 64 mb_internal_memory [7] => 32_expandable_memory [8] => 1200_standard_battery_type [9] => 3_size [10] => 1000_standard_battery_type [11] => touch and type_type ) ) [productsubcategory] => Array ( [1] => Array ( [0] => karbonn_brandname [1] => touch and type_type [2] => micromax_brandname [3] => 2.8_size [4] => gsm_sim_support [5] => 3.15_primary_camera [6] => 52 mb_internal_memory [7] => 8_expandable_memory [8] => 1000_standard_battery_type [9] => nokia_brandname [10] => symbian s40_os_clean [11] => 5_primary_camera [12] => 128 mb_ram [13] => 256 mb_internal_memory [14] => 32_expandable_memory [15] => 1110_standard_battery_type [16] => gsm + gsm_sim_support [17] => 2_primary_camera [18] => 32 mb_ram [19] => 10 mb_internal_memory [20] => no_expandable_memory [21] => 1020_standard_battery_type [22] => 680 mhz_processor [23] => 64 mb_ram [24] => 128 mb_internal_memory [25] => 860_standard_battery_type [26] => blackberry_brandname [27] => 2.45_size [28] => 1 ghz_processor ) ) ); Desired array : $array = array ( [0] => sony_brandname [1] => touch and type_type [2] => 2.8_size [8] => 1000_standard_battery_type [16] => gsm + gsm_sim_support [17] => 2_primary_camera )
Use array_intersect(): $result = array_intersect($array["brandname"][0], $array["productsubcategory"][1]); print_r($result);
How can I process this string so I end up with an array that just contains the full name & the associated jpg URL for each entity?
I have the following string which I need to extract the full name plus the URI/URL associated with it into an array for each one. It's not constructed like typical data, so I am unsure how to proceed. I thought explode at first, but there is "garbage" data in the beginning not needed, so I need a way to maybe cleanse the data first? But maybe there is an efficient way of doing this in one or two steps/stages so my code is efficient? After some research I am thinking mb_split() but I am very poor at constructing regex. Need some direction here... In my example below, you can see the data pattern that emerges after the initial "junk". The 3rd "row" for each grouping that forms is where the meat (aka data) that I seek is. The first string in that first grouping, in the 3rd row in the example is "Amanda Grider". This is the full name and its position in the returned data example I am looking for from each grouping. Further along that row is the URI/URL for the jpg image, which is the second piece of data I seek. Everything else as far as I am concerned is garbage and can get tossed. What is the fastest, most efficient way to process this chunk and get the values I seek into an array so i can use this in my work? (BTW, the following code I hand added return characters to make the data more easily understood. In reality, there are no return characters and it presents as one big string) [ [ "tsg.lac", [], [ [ [null,null,"100829745667958569941"], [], ["Amanda Grider",null,null,null,"4b3347c83f0a1","8nwbFHob02C8CmojHF","BoZrAHx801Rz8o3h8k",null,"https://lh3.googleusercontent.com/-zIK8ZN_ZDt8/AAAAAAAAAAI/AAAAAAAAAAA/fsiR92bLDlU/photo.jpg",null,1,"Marina del Rey, CA",null,null,null,0,null,[],null,null,null,""], [] ],[ [null,null,"115014076410206782853"], [], ["VWvortex",null,null,null,"4b13c6667b3c9","JKCGFo_CApJ","JKCGFo_CApJ",null,"//lh6.googleusercontent.com/-X_wSt8nwpOU/AAAAAAAAAAI/AAAAAAAAACQ/R_jcIPcegbM/photo.jpg",null,1,null,null,null,null,0,null,[],[null,"http://WWW.VWVORTEX.COM",null,null,3],null,null,"World's largest Volkswagen enthusiast community and blog."], [] ],[ [null,null,"102608018926739248428"], [], ["Wale",null,null,null,"4b1ded89a3721","JmRxAk","JmRxAk",null,"//lh4.googleusercontent.com/-xyeyjc4Avow/AAAAAAAAAAI/AAAAAAAAABU/SY-9EKeDnhw/photo.jpg",null,1,null,null,null,null,0,null,[],[null,"http://www.ralphfolarin.com/",null,null,6],null,null,""], [] ],[ [null,null,"114161985228080012446"], [], ["The Opus Rhythm Music Blog",null,null,null,"4b177a5207d09","IIJj03C4Iog3HIKMIIJz02xEHnRf01ZxFnB","IIJj03C4Iog3HIKMIIJz02xEHnRf01ZxFnB",null,"//lh5.googleusercontent.com/-4QRl1IgDCLU/AAAAAAAAAAI/AAAAAAAAABI/pVoxTQ7SH8Y/photo.jpg",null,1,null,null,null,null,0,null,[],[null,"http://www.bacchusentertainment.com",null,null,6],null,null,"We are the team music blog of Bacchus Entertainment"], [] ],[ [null,null,"114645267718535118440"], [], ["Jalopnik",null,null,null,"4b12fccb6f809","DHRxFoK0Cng","DHRxFoK0Cng",null,"//lh6.googleusercontent.com/-_M1nn9mKyY8/AAAAAAAAAAI/AAAAAAAAABI/aXhkyN7cuuk/photo.jpg",null,1,null,null,null,null,0,null,[],[null,"http://jalopnik.com/",null,null,3],null,null,"Jalopnik: Drive Free or Die"], [] ],[ [null,null,"105503202599719238167"], [], ["Audi USA",null,null,null,"4b14db7535e99","8owhCkGEHmR","8owhCkGEHmR",null,"//lh3.googleusercontent.com/-mHHyVhWfARE/AAAAAAAAAAI/AAAAAAAAAC4/Qn0lYbilT8M/photo.jpg",null,1,null,null,null,null,0,null,[],[null,"http://www.audiusa.com","(800) 822-2834",null,3],null,null,"Progress is social media, and listening, and fans, and Google+. So here we are."], [] ],[ [null,null,"104108787932235341403"], [], ["Audi Sport",null,null,null,"4b23243c864b1","8owhCkGAGJC8IF","8owhCkGAGJC8IF",null,"//lh4.googleusercontent.com/-jGBNL9dbwYs/AAAAAAAAAAI/AAAAAAAAAUA/pgsAqvaX8XM/photo.jpg",null,1,null,null,null,null,0,null,[],[null,"http://www.facebook.com/AudiSportPage",null,null,6],null,null,"Unofficial Audi Sport fan page, not affiliated with or endorsed by Audi AG."], [] ],[ [null,null,"106689856342933829975"], [], ["Volkswagen USA",null,null,null,"4b20ca9b7fa69","JJBxDohI8nBjFFGEHmR","JJBxDohI8nBjFFGEHmR",null,"//lh5.googleusercontent.com/-i3MO9CsymQ8/AAAAAAAAAAI/AAAAAAAAAB4/ddmTW3D8s20/photo.jpg",null,1,null,null,null,null,0,null,[],[null,"http://www.vw.com","(800) 822-8987",null,3],null,null,"Take a look around, kick the tires, ask questions and get to know our community."], [] ],[ [null,null,"115425298803319911308"], [], ["Internal Frequency",null,null,null,"4b177b6d46119","Co4CAo_08no3BJZjGowjFHhM","Co4CAo_08no3BJZjGowjFHhM",null,"//lh4.googleusercontent.com/-lZeecuGL3Ig/AAAAAAAAAAI/AAAAAAAAABk/Afv5eGuBzUM/photo.jpg",null,1,null,null,null,null,0,null,[],[null,"http://www.internalfrequency.com",null,null,6],null,null,"The 1st hand ups-and-downs of the CEO of an up-and-coming entertainment label in Southern California"], [] ],[ [null,null,"101358795463286919640"], [], ["Music Think Tank",null,null,null,"4b1947fea8251","EoxACmg3IIJrFIg3IHS0Dk","EoxACmg3IIJrFIg3IHS0Dk",null,"//lh4.googleusercontent.com/-B2KTfl4uNyE/AAAAAAAAAAI/AAAAAAAAACM/N955ZhPV08E/photo.jpg",null,1,null,null,null,null,0,null,[],[null,"http://www.musicthinktank.com",null,null,6],null,null,"Where the music industry speaks out loud. Create the Chaos."], [] ] ] ] ] UPDATE: So I stumbled on something and discovered the data is in fact valid JSON, does get decoded and passed back but still something odd and seems very complex (too complex for what I need). I use json_decode() to prase the data, which then is assigned to the variable $jsondata. When I added the following immediately after that: print_r ( print_r($jsondata)); I got this (I added return characters so it makes more sense and can be easily read): Array ( [0] => Array ( [0] => tsg.lac [1] => Array () [2] => Array ( [0] => Array ( [0] => Array ( [0] => [1] => [2] => 100829745667958569941 ) [1] => Array ( ) [2] => Array ( [0] => Amanda Grider [1] => [2] => [3] => [4] => 4b33843806e03 [5] => 8nwbFHob02C8CmojHF [6] => BoZrAHx801Rz8o3h8k [7] => [8] => https://lh3.googleusercontent.com/-zIK8ZN_ZDt8/AAAAAAAAAAI/AAAAAAAAAAA/fsiR92bLDlU/photo.jpg [9] => [10] => 1 [11] => Marina del Rey, CA [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => [19] => [20] => [21] => ) [3] => Array ( ) ) [1] => Array ( [0] => Array ( [0] => [1] => [2] => 115014076410206782853 ) [1] => Array ( ) [2] => Array ( [0] => VWvortex [1] => [2] => [3] => [4] => 4b13c6667b3c9 [5] => JKCGFo_CApJ [6] => JKCGFo_CApJ [7] => [8] => //lh6.googleusercontent.com/-X_wSt8nwpOU/AAAAAAAAAAI/AAAAAAAAACQ/R_jcIPcegbM/photo.jpg [9] => [10] => 1 [11] => [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => Array ( [0] => [1] => http://WWW.VWVORTEX.COM [2] => [3] => [4] => 3 ) [19] => [20] => [21] => World's largest Volkswagen enthusiast community and blog. ) [3] => Array ( ) ) [2] => Array ( [0] => Array ( [0] => [1] => [2] => 102608018926739248428 ) [1] => Array ( ) [2] => Array ( [0] => Wale [1] => [2] => [3] => [4] => 4b1ded89a3721 [5] => JmRxAk [6] => JmRxAk [7] => [8] => //lh4.googleusercontent.com/-xyeyjc4Avow/AAAAAAAAAAI/AAAAAAAAABU/SY-9EKeDnhw/photo.jpg [9] => [10] => 1 [11] => [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => Array ( [0] => [1] => http://www.ralphfolarin.com/ [2] => [3] => [4] => 6 ) [19] => [20] => [21] => ) [3] => Array ( ) ) [3] => Array ( [0] => Array ( [0] => [1] => [2] => 114161985228080012446 ) [1] => Array ( ) [2] => Array ( [0] => The Opus Rhythm Music Blog [1] => [2] => [3] => [4] => 4b177a5207d09 [5] => IIJj03C4Iog3HIKMIIJz02xEHnRf01ZxFnB [6] => IIJj03C4Iog3HIKMIIJz02xEHnRf01ZxFnB [7] => [8] => //lh5.googleusercontent.com/-4QRl1IgDCLU/AAAAAAAAAAI/AAAAAAAAABI/pVoxTQ7SH8Y/photo.jpg [9] => [10] => 1 [11] => [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => Array ( [0] => [1] => http://www.bacchusentertainment.com [2] => [3] => [4] => 6 ) [19] => [20] => [21] => We are the team music blog of Bacchus Entertainment ) [3] => Array ( ) ) [4] => Array ( [0] => Array ( [0] => [1] => [2] => 114645267718535118440 ) [1] => Array ( ) [2] => Array ( [0] => Jalopnik [1] => [2] => [3] => [4] => 4b12fccb6f809 [5] => DHRxFoK0Cng [6] => DHRxFoK0Cng [7] => [8] => //lh6.googleusercontent.com/-_M1nn9mKyY8/AAAAAAAAAAI/AAAAAAAAABI/aXhkyN7cuuk/photo.jpg [9] => [10] => 1 [11] => [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => Array ( [0] => [1] => http://jalopnik.com/ [2] => [3] => [4] => 3 ) [19] => [20] => [21] => Jalopnik: Drive Free or Die ) [3] => Array ( ) ) [5] => Array ( [0] => Array ( [0] => [1] => [2] => 105503202599719238167 ) [1] => Array ( ) [2] => Array ( [0] => Audi USA [1] => [2] => [3] => [4] => 4b14db7535e99 [5] => 8owhCkGEHmR [6] => 8owhCkGEHmR [7] => [8] => //lh3.googleusercontent.com/-mHHyVhWfARE/AAAAAAAAAAI/AAAAAAAAAC4/Qn0lYbilT8M/photo.jpg [9] => [10] => 1 [11] => [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => Array ( [0] => [1] => http://www.audiusa.com [2] => (800) 822-2834 [3] => [4] => 3 ) [19] => [20] => [21] => Progress is social media, and listening, and fans, and Google+. So here we are. ) [3] => Array ( ) ) [6] => Array ( [0] => Array ( [0] => [1] => [2] => 104108787932235341403 ) [1] => Array ( ) [2] => Array ( [0] => Audi Sport [1] => [2] => [3] => [4] => 4b23243c864b1 [5] => 8owhCkGAGJC8IF [6] => 8owhCkGAGJC8IF [7] => [8] => //lh4.googleusercontent.com/-jGBNL9dbwYs/AAAAAAAAAAI/AAAAAAAAAUA/pgsAqvaX8XM/photo.jpg [9] => [10] => 1 [11] => [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => Array ( [0] => [1] => http://www.facebook.com/AudiSportPage [2] => [3] => [4] => 6 ) [19] => [20] => [21] => Unofficial Audi Sport fan page, not affiliated with or endorsed by Audi AG. ) [3] => Array ( ) ) [7] => Array ( [0] => Array ( [0] => [1] => [2] => 106689856342933829975 ) [1] => Array ( ) [2] => Array ( [0] => Volkswagen USA [1] => [2] => [3] => [4] => 4b20ca9b7fa69 [5] => JJBxDohI8nBjFFGEHmR [6] => JJBxDohI8nBjFFGEHmR [7] => [8] => //lh5.googleusercontent.com/-i3MO9CsymQ8/AAAAAAAAAAI/AAAAAAAAAB4/ddmTW3D8s20/photo.jpg [9] => [10] => 1 [11] => [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => Array ( [0] => [1] => http://www.vw.com [2] => (800) 822-8987 [3] => [4] => 3 ) [19] => [20] => [21] => Take a look around, kick the tires, ask questions and get to know our community. ) [3] => Array ( ) ) [8] => Array ( [0] => Array ( [0] => [1] => [2] => 115425298803319911308 ) [1] => Array ( ) [2] => Array ( [0] => Internal Frequency [1] => [2] => [3] => [4] => 4b177b6d46119 [5] => Co4CAo_08no3BJZjGowjFHhM [6] => Co4CAo_08no3BJZjGowjFHhM [7] => [8] => //lh4.googleusercontent.com/-lZeecuGL3Ig/AAAAAAAAAAI/AAAAAAAAABk/Afv5eGuBzUM/photo.jpg [9] => [10] => 1 [11] => [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => Array ( [0] => [1] => http://www.internalfrequency.com [2] => [3] => [4] => 6 ) [19] => [20] => [21] => The 1st hand ups-and-downs of the CEO of an up-and-coming entertainment label in Southern California ) [3] => Array ( ) ) [9] => Array ( [0] => Array ( [0] => [1] => [2] => 101358795463286919640 ) [1] => Array ( ) [2] => Array ( [0] => Music Think Tank [1] => [2] => [3] => [4] => 4b1947fea8251 [5] => EoxACmg3IIJrFIg3IHS0Dk [6] => EoxACmg3IIJrFIg3IHS0Dk [7] => [8] => //lh4.googleusercontent.com/-B2KTfl4uNyE/AAAAAAAAAAI/AAAAAAAAACM/N955ZhPV08E/photo.jpg [9] => [10] => 1 [11] => [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => Array ( [0] => [1] => http://www.musicthinktank.com [2] => [3] => [4] => 6 ) [19] => [20] => [21] => Where the music industry speaks out loud. Create the Chaos. ) [3] => Array ( ) ) ) ) ) 1 Now that is ALOT of arrays! Not only that, I only require the super nested array [2] where the name starts and of that values [0] & [8] only! Then I get an error when this next line (below) runs but I am less concerned with that, I want to know how can I trim down this data so it doesn't become such a memory hog.... $visiblepeople = $jsondata[2];
To me this looks like JSON ( http://www.json.org ), and thus, you can use any JSON implementation to parse it. For Python, there's a module called ... json ;-) See http://docs.python.org/library/json.html.
PHP Accessing decoded JSON
I have a PHP script which successfully decodes a JSON string into a PHP object using: $decodedJSON = json_decode($responseString); And when $decodedJSON is printed to the response, I get: stdClass Object ( [response] => stdClass Object ( [total_rows] => 2379 [data] => Array ( [0] => Array ( [0] => zPKfssdfg456hwCQp6XpogfTsjc [1] => 3456gg4-b7ea-4bcf1680c619 [2] => Title Description Here. [3] => Example Address [4] => [5] => [6] => Exmaple City [7] => CA [8] => US [9] => 95616 [10] => (555) 555-1212 [11] => [12] => Food & Beverage [13] => [14] => [15] => 62.79901 [16] => -92.80102 [17] => 1 ) [1] => Array ( [0] => zPKfl6ylrwCQp6XpogfTsjc [1] => 98e9945a-b7ea-4bcf1680c619 [2] => Title Description Here. [3] => Example Address [4] => [5] => [6] => Exmaple City [7] => CA [8] => US [9] => 95616 [10] => (555) 555-1212 [11] => [12] => Food & Beverage [13] => [14] => [15] => 62.79901 [16] => -92.80102 [17] => 1 ) ) [fields] => Array ( [0] => subject_key [1] => factual_id [2] => name [3] => address [4] => address_extended [5] => po_box [6] => locality [7] => region [8] => country [9] => postcode [10] => tel [11] => fax [12] => category [13] => website [14] => email [15] => latitude [16] => longitude [17] => status ) [rows] => 10 [cache-state] => CACHED [big-data] => 1 [subject_columns] => Array ( [0] => 1 ) ) [version] => 2 [status] => ok ) My question is this: how do I access the "fields" data? I've tried using $decodedJSON["fields"] as well as $decodedJSON[0]["fields"] and $decodedJSON[0][2] and many many more variations. Does anyone see what I am doing wrong? Many thanks, Brett
Try using $decodedJSON->response->fields
Well you can decode it to an associated array: $decodedJSON = json_decode($responseString, true); and then you can access as you were trying OR: $decodedJSON->response->fields