Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I cannot seem to be able to use the variable into the array. It must be a syntax error.
Please, help me sort this out.
$id=$_POST['eventid'];
$data = array('message' => $id);
$id content is null.
Thanks.
Your coding is nice except the $_POST value is not getting fetched. I have commented the POST var just to make sure your code works fine.
<?php
$id='test';//$_POST['eventid'];
$data = array('message' => $id);
print_r($data);//output : Array ( [message] => test )
?>
$id = $_POST['eventid'];
$data = array('message' => $id);
If $id is null, it means that $_POST['eventid'] is null.
Also, are you sure that it is actually null, and not a blank string? Because there's a slight difference between the two.
My guess is that $_POST['eventid'] does not exist or the value is an empty string.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I looked at the question for maximum from associative array but I am looking for one liner. I have array like following,
$studenRsults=array(
array(
'roll'=>1,
'name'=>'jack Smit',
'marks'=>70
),
array(
'roll'=>4,
'name'=>'Sita',
'marks'=>50
),
array(
'roll'=>2,
'name'=>'Akhilesh',
'marks'=>80
),
array(
'roll'=>3,
'name'=>'jon',
'marks'=>50
),
);
Please suggest one liner thanks.
This needs php 5.5+ for array_column
$max = max(array_column($studenRsults, 'marks'));
or php 5.3+ for lamdas
$max = max(array_map(function($el){ return $el['marks']; }, $studenRsults));
Assuming you mean max of roll. But yeah, code quality isn't measured in how few lines you have...
foreach($studenRsults as $result) $maxResult = (isset($maxResult['roll']) && ($maxResult['roll'] > $result['roll'])) ? $maxResult : $result;
print_r($maxResult); // print the max roll student
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Can anyone help me get the value of IFC/USD 0.00001031 from the webpage http://infinitecoin.com.
I need to grab the value after IFC/USD..
The way I thought to do it was to:
$file_string = file_get_contents('http://infinitecoin.com');
preg_match('/IFC/USD plus next 11 charecters', $file_string, $title);
$value = $title[1];
echo $title_out ;
But im not sure how to ask PHP to find IFC/USD then return the next 11 characters after that.
If I could accomplish this, my task would be solved..
Any help would be great.
Thank you
Jason
$output = array();
preg_match("/(?<=IFC\/USD\s)[\d\.]+/", 'IFC/USD 0.00001015', $output);
$output will look like this:
Array
(
[0] => 0.00001015
)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Sorry for another noob question, but... Can someone please explain to me what the function myfunction is actually doing. I understand it's checking if the variables $a and $b are identical and than it's suppose to return 0 if they're identical but the next return is confusing. I see their using the ternary operators.
function myfunction($a,$b)
{
if ($a===$b)
{
return 0;
}
return ($a>$b)?1:-1;
}
$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("a"=>"red","b"=>"green","d"=>"blue");
$a3=array("e"=>"yellow","a"=>"red","d"=>"blue");
$result=array_diff_uassoc($a1,$a2,$a3,"myfunction");
print_r($result);
the print_r returns
Array ( [c] => blue )
but how did we get here...
As stated in the documentation of array_diff_uassoc, it returns the entries from first argument that are unique compared to other arguments. And the last argument is the name of the function it uses to check whether item is unique or not.
So because only $a1 contains 'c'=>'blue' it is returned.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I got a object like this:
{"1":"FFS","2":"S"}, and I use json_decode function to convert it into an array, but I am not success with it. It becomes the array like this: {"FFS", "S"}, but missing the {"1", "2"}, Can I convert it to become a dict or something, that I can access both value? Thanks.
use true param, to convert object to associative array for json_decode(), like do:
$str = '{"1":"FFS","2":"S"}';
echo "<pre>"; print_r(json_decode($str, true));
gives::
Array
(
[1] => FFS
[2] => S
)
$myjsonobject = json_decode('{"1":"FFS","2":"S"}');
Should working.
Try: print_r($myjsonobject); to validate.
Its working.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
if(preg_match("/^[\w_.]+$/",stripslashes($_GET['key']))) {
$key = $wpdb->escape(stripslashes($_GET['key']));
}
assuming the key value is = be4e53680e6518cca701ec091258642f0740fe3d
can someone please explain me the if condition ? I`m confused on what exactly it checks for
ok thanks guys for the clarification on that.
now i`m posting one more line of code that ties with this one. if u can help me understand it.
if(preg_match("/^[\w_.]+$/",stripslashes($_GET['key']))) {
$key = $wpdb->escape(stripslashes($_GET['key']));
} else {
if(preg_match("/^[\w_.]+$/",$name)) {
$wpdb->query("some query;");
}
exit(0);
}
assuming $_GET['key'] = be4e53680e6518cca701ec091258642f0740fe3d
$name = TomJones
what i got so far is:
If $_GET['key'] is numeric then $key = stripslashes (get_key)
but when does the else kiks in ?
it looks for strings containing alphanumeric characters, underscores and dots in the key param from request, underscore is ommitable because \w handles it