I want to show only 1 data in array.
My code right now:
var_dump($ranked);
In others cases, I have used echo $ranked->tier but in array this won't work.
You can do it like this:
echo $ranked['tier'];
var_dump($ranked['tier']);
or:
echo $ranked['tier'];
Related
This is the data that i need to extract like example profile_contact_numbers
so the output will be +639466276715
how can i do it in php code??
any help will do regards
a:2:
{s:23:"profile_contact_numbers";s:13:"+639466276715";s:16:"profile_position";s:7:"Courier";}
I'm not sure 100% this can go into an array but try the unserialize function
$json_resp = {your values};
$array[] = unserialize($json_resp);
To check if it has gone into an array print_r on $array.
Read this link if the code above doesn't work
http://php.net/manual/en/function.unserialize.php
I have managed to fix it
$serialized = array(unserialize('a:2:{s:23:"profile_contact_numbers";s:13:"+639466276715";s:16:"profile_position";s:7:"Courier";}'));
var_dump($serialized);
use code :
$var = preg_split('["]','{s:23:"profile_contact_numbers";s:13:"+639466276715";s:16:"profile_position";s:7:"Courier";}');
echo $var[1].'='.$var[3]; // profile_contact_numbers=+639466276715
echo $var[5].'='.$var[7]; // profile_position=Courier
Hello I would like to store string which comes from json encode to get it store in MySQL, but the thing is that the array returned nothing. Here is my code:
$com = array("1-1","1-2","1-3");
$classcom=array();
for ($i=1; $i<(int)$totaleleve; $i++) {
$eleve=array();
foreach($com as $value)
{
array_push($eleve,'2');
}
$final="'".json_encode($eleve)."'";
array_push($classcom,$final);
echo $final;
echo $classcom;
}
echo $classcom;
For your information, $totaleleve='20', and I do $final="'".json_encode($eleve)."'"; so that I can concentrate strings of the array to be able to insert it into the SQL statement, which looks something like this:
$sql="INSERT INTO table VALUES (".explode(",", $classcom).")"
// so that it looks like something like this:
$sql="INSERT INTO table VALUES ('["2","2","2"]','["2","2","2"]','["2","2","2"]')
the $final gave me '["2","2","2"]' which i wanted, but when i do array_push($classcom,$final);, it just gave me a blank array :
Array
Can someone help me, please? Thank you!
If $totaleleve is greater than 0 the array is not empty. Just use print_r or var_dump to show its values.
print_r($classcom)
Instead of echo $classcom
Just write print_r($classcom); instead of echo $classcom; and you will see that your array isn't empty.
Can someone tell me how I can loop through the below array?
http://pastebin.com/rhaF5Zdi
I've tried with out luck:
$_data = json_decode($_data);
foreach ( $_data as $tweet )
{
echo "{$tweet->text}\n";
}
thanks
ps: im follwoing this php script.
http://mikepultz.com/2013/06/mining-twitter-api-v1-1-streams-from-php-with-oauth/
hers another paste bin on the array. there seems to be multiple arrays happening
http://pastebin.com/dduzhpqY
It looks like you might be creating a PHP stnd object instead of an array
//this will create a php standard object
$objOfData=json_decode($json);
Instead Use the version below: (Notice the the 2nd parameter is TRUE)
$associativeArray=json_decode($json, TRUE);
This will turn the object into an associative array and you can access fields like so:
$id=$associativeArray['id'];
More info here: json_decode
The code in posted link is not JSON, but it is output of print_r() function. PHP has no invert function to print_r(), but on php.net in print_r() documentation's comments you can find some user-made functions which can read it.
For example this one:
http://www.php.net/manual/en/function.print-r.php#93529
I hope it will help. Good Luck :)
Ended up using:
if(array_key_exists('text', $_data)){
echo 'Tweet ID = '.$_data['id_str'];
echo 'Tweet Text = '.$_data['text'];
echo '<br /><br />';
}
cheers
I'm breaking my brain on a array from a query in MYSQL that i want to pass to a javascript array.
In the query i select the array with a GROUP CONCAT and the outcome looks like:
1358121600,1,1,0,0,0,0,0,0,1358380800,2,2,0,0,0,0,0,0,1358640000,1,1,0,0,0,0,0,0,1360454400,3,3,0,0,0,0,0,0,1360972800,1,1,0,0,0,0,0,0
But if i use JSON_Encode like this:
<?php echo 'var prijzen = new Array('.json_encode($array_prijzen).');'; ?>
I looks like the array is filled and i can also alert the array, but if i alert prijzen[0] it gives "undefined".
The following code should fix your problem:
<?php echo 'var prijzen = ['.$array_prijzen.'];'; ?>
Building on #datasages 's answer. If $array_prijzen is a genuine php array, then the following will work. I think datasages's answer is based on the fact that your variable named $array_prijzen is actually a string (which seems to be the case). But if it's an array, then do the following (i created a five element array as an example):
<?php $array_prijzen = array(1358121600,1,1,0,0); echo 'var prijzen = ['.implode(",",$array_prijzen).'];'; ?>
Hey guys I need help on passing multiple values for my PHP
http://s596.beta.photobucket.com/user/kingbookal/media/Capture.png.html?sort=3&o=0
That's the code from the 1st page and for the next page it is
$year = $_GET['yearlevel'];
I tried to alert the value but its null.
Please guide me well..
https://www.dropbox.com/sh/fokl2hnrjtpsfbn/Rcm8EfApm1
This is the link for my scripts
Do you want to echo the value from a key inside an array? Then you do like this:
echo $rowProfName['professor_name'];
If it doesn't return anything, you could check if a key exists in the array by using the following code:
if(!isset($rowProfName['professor_name']))
{
echo "Array key 'professor_name' is not set.";
}
If you want to check what your array contains, simply run this code:
$yourArray=array("value1","value2");
print_r($yourArray);
//If you want clean output as HTML, use this:
echo "<pre>";
print_r($yourArray);
echo "</pre>";
I hope I understood your question.