Neo4j ResultSet Object - how to get data if result is an array - neo4j

I have one gremlin query in which I used cap().next()
and Everyman\Neo4j\Query\ResultSet Object is
...
[data:protected] => Array
(
[v[1079]] => Array
(
[0] => 14
)
[v[1082]] => Array
(
[0] => 25
)
[v[1016]] => Array
(
[0] => 5
)
[v[1078]] => Array
(
[0] => 10
)
[v[1081]] => Array
(
[0] => 17
)
)
...
how to get that array?
$result[0][0] is not working.

To iterate ResultSets use
foreach ($result as $row) {
echo $row['x']->getProperty('your_property') . "\n";
}
or with scalar values in column y
foreach ($result as $row) {
echo $row['x']->getProperty('your_property') . ": " . $row['y'] ."\n";
}
It would be nice to have the original gremlin query thought to see what you are returning from it.
see github

Related

unset not deleting key in multidimensional array

I have multidimensional array and wants to remove delivery location where ever it exists
Array
(
[0] => Array
(
[amountReceived] => 1
[deliveryLocation] => germany
)
[1] => Array
(
[amountReceived] => 2
[deliveryLocation] => bulgaria
)
)
PHP
foreach ($arr as $val)
{
foreach($val as $k => $v)
{
if($k == 'deliveryLocation')
{
unset($arr[$k]);
}
}
}
return $arr;
problem is it's returning above array as it is without removing any key from it.
Easy and fast to understand way
$t=0;
foreach ($arr as $val)
{
unset($arr[$temp]['deliveryLocation']);
$t++;
}

Index in foreach starts not with 0

$rounds = $season->championsLeague->rounds->where('stage', 'Olympic')->take(2);
$indexes = [];
foreach ($rounds as $index => $round) {
$indexes[] = $index;
}
echo '<pre>';print_r($indexes);echo '<pre>';
And I receive in indexes: Array
(
[0] => 6
[1] => 7
)
How it is possible?
Why not Array
(
[0] => 0
[1] => 1
)
The slice, chunk, and reverse methods now preserve keys on the collection. If you do not want these methods to preserve keys, use the values method on the Collection instance. This is from laravel documentation. I think it is true for take method also.

AFNetworking - Request format is not proper when using dictionaries

I'm sending a dictionary 'childDetails' which has a dictionary (rewards) as one of its objects.
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:url parameters:childDetails constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
This "rewards" dictionary has two keys "name" and "value" which looks like {#"name",#"Reward 1",#"value",#"10"}.
when this gets posted to the server, the server receives it as follows;
Array
(
[group_id] => 5
[name] => John Doe
[rewards] => Array
(
[0] => Array
(
[name] => Sample reward 2
)
[1] => Array
(
[value] => 50
)
[2] => Array
(
[name] => Sample Reward 1
)
[3] => Array
(
[value] => 10
)
)
[tasks] => Array
(
[0] => Array
(
[title] => Default task one
)
[1] => Array
(
[title] => Default task two
)
[2] => Array
(
[title] => Default task five
)
)
[token] => 5332884c2bc8c5
)
Any Idea how to fix this?
Any help is much appreciated.
Thanks in advance
I think the "parameters: param of POST: only accepts key/value pairs. Are you sure you don't have to serialize manually your objects first ?
Can you print the content of "childDetails" please ?
I found out that inorder to get it to work, you have to reformat your dictionary.
In my case I had to change it as;
NSDictionary *parameters = #{
#"rewards": #[
{#"reward name",#"reward value"},
{#"reward name",#"reward value"}
]
};;

Twitter API call not working

Hi Friends i am trying to run twitter apis to get tweets for a hashtag using below code. When i tried get the user timeline it's not giving any error for authentication but when it tried to search for tweets which contains hahstag it's giving authentication error.
$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$token_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$consumer_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$consumer_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$host = 'api.twitter.com';
$method = 'GET';
$path = '/1.1/statuses/user_timeline.json'; // api call path
$query = array( // query parameters
'screen_name' => 'twitterapi'
);
$oauth = array(
'oauth_consumer_key' => $consumer_key,
'oauth_token' => $token,
'oauth_nonce' => (string)mt_rand(), // a stronger nonce is recommended
'oauth_timestamp' => time(),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_version' => '1.0'
);
$oauth = array_map("rawurlencode", $oauth); // must be encoded before sorting
$query = array_map("rawurlencode", $query);
$arr = array_merge($oauth, $query); // combine the values THEN sort
asort($arr); // secondary sort (value)
ksort($arr); // primary sort (key)
// http_build_query automatically encodes, but our parameters
// are already encoded, and must be by this point, so we undo
// the encoding step
$querystring = urldecode(http_build_query($arr, '', '&'));
$url = "https://$host$path";
// mash everything together for the text to hash
$base_string = $method."&".rawurlencode($url)."&".rawurlencode($querystring);
// same with the key
$key = rawurlencode($consumer_secret)."&".rawurlencode($token_secret);
// generate the hash
$signature = rawurlencode(base64_encode(hash_hmac('sha1', $base_string, $key, true)));
// this time we're using a normal GET query, and we're only encoding the query params
// (without the oauth params)
$url .= "?".http_build_query($query);
$url=str_replace("&","&",$url); //Patch by #Frewuill
$oauth['oauth_signature'] = $signature; // don't want to abandon all that work!
ksort($oauth); // probably not necessary, but twitter's demo does it
// also not necessary, but twitter's demo does this too
function add_quotes($str) { return '"'.$str.'"'; }
$oauth = array_map("add_quotes", $oauth);
// this is the full value of the Authorization line
$auth = "OAuth " . urldecode(http_build_query($oauth, '', ', '));
echo $auth;exit;
// if you're doing post, you need to skip the GET building above
// and instead supply query parameters to CURLOPT_POSTFIELDS
$options = array( CURLOPT_HTTPHEADER => array("Authorization: $auth"),
//CURLOPT_POSTFIELDS => $postfields,
CURLOPT_HEADER => false,
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false);
// do our business
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);
$twitter_data = json_decode($json);
echo "<pre>";print_r($twitter_data);
When i run this code i am successfully able to get the user time line so i wnt for next step to get tweets for a particular hashtag by chnaging code like below
$host = 'api.twitter.com';
$method = 'GET';
$path = '/1.1/search/tweets.json'; // api call path
$query = array( // query parameters
'q' => '#Polls2013'
);
But now it's giving a weird error like below.
stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[message] => Could not authenticate you
[code] => 32
)
)
)
The query you are posting for search should be url encoded in the manner specified by twitter,
See this documentation (https://dev.twitter.com/docs/auth/percent-encoding-parameters)

How to: parse a string 'mm/yyyy' into a date in PHP5.3?

I come from Java & C# worlds, and just wondering how do I parse a string formatted as mm/yyyy into a date in PHP 5.3.
I've tried with the following:
date_parse_from_format('mm/yyyy', '05/2013');
Then the returned array complains with errors:
[2] => Unexpected data found.
[5] => The separation symbol could not be found
[7] => Data missing
How to parse to date a string formatted as mm/yyyy in PHP 5.3?
Here is the complete var_dump:
Array
(
[year] => 2013
[month] => 20
[day] =>
[hour] =>
[minute] =>
[second] =>
[fraction] =>
[warning_count] => 0
[warnings] => Array
(
)
[error_count] => 3
[errors] => Array
(
[2] => Unexpected data found.
[5] => The separation symbol could not be found
[7] => Data missing
)
[is_localtime] =>
)
Use 'm/Y' instead of 'mm/yyyy'. Look at the date() function for details.
date_parse_from_format('m/Y', '05/2013');
What to do next...first of all I'd use Object oriented style:
$date = DateTime::createFromFormat('m/Y', '05/2013');
// 2013-05
echo $date->format('Y-m');
// 1369946144 UNIX timestamp
echo $timestamp = $date->format('U');
// 2013-05 using date(), procedural style
echo date('Y-m', $timestamp );

Resources