How can I access the id value in this array? [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
When I do a print_r I get this array:
Array (
[0] => Array (
[id] => 5280
)
)
How can I access the id value with PHP?

You can access it like this
$id_value = $your_array[0]['id'];

Try
$mapped = array_map("current",$array);
echo $mapped[0];
This is useful if you have multiple arrays on the root array
eg: Array(Array(),Array()..)

Related

How to convert array to different type [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
i have Array ( [0] => dev2 [1] => dev3 [2] => dev4 )
how to convert to ["dev2","dev3","dev4"]
$old_array = array( 'dev2', 'dev3', 'dev4');
$new_array = json_encode($old_array);
echo $new_array;
I hope this is what you want.

How to get rating value (WordPress) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
$rating = $rowsRaing;
Array
(
[0] => stdClass Object
(
[ratting] => 2.5
)
)
I want rating value.
I want user average number of ratting help me
Thanks
Your query should be
$rowsRaing = $wpdb->get_results("select avg(ratting) as rating from tablename where id='".$_REQUEST['id']."'");
$rat=$rowsRaing;
$RatingVal = $rat[0]->rating;
By using this variable you get the avg number of ratting
"$RatingVal"
It's var of object inside array, so:
$yourRatingValue = $rat[0]->rating;

PHP Select MYSQL select id from Array [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Hello I have this array:
$_SESSION['id'] = array();
I would like to select all array ID'S and then select them from the database.
How to do it? I have no idea..
$sql='select name from table where id in ('.implode(",",$_SESSION['id']).')';

Echoing several variable in random order [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm making simple test script with PHP+mysql.
The script gives the question and SELECT with 4 options (answers).
1 of them is correct, 3 others are incorrect, retrieved from mysql table.
I have 4 variables and all works fine, but I need to retrieve these variables in random order.
$variable1='1';
$variable2='2';
$variable3='3';
$variable4='4';
Just need some direction what to learn, what method to use.
Many thanks in advance
SELECT data from MySQL
Store in an associative array
shuffle the array
http://codepad.org/6R9LsGIy
<?php
$arrAnswers = array("a", "b", "c", "d");
shuffle($arrAnswers);
print_r($arrAnswers);
/* Example Ouput:
Array
(
[0] => b
[1] => d
[2] => a
[3] => c
) */
As you've said you have these variables;
$variable1='1';
$variable2='2';
$variable3='3';
$variable4='4';
$arrAnswers = array($variable1,$variable2,$variable3,$variable4);
There are more elegant ways, but with the information given, this is the best I can do :)

Passing PHP Array to XSL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
My Array ($arr) is:
Array
(
[0] => Array
(
[partners_id] => 2
)
[1] => Array
(
[partners_id] => 5
)
[2] => Array
(
[partners_id] => 6
)
)
I'm passing PHP Array using
$this->xsl->setParameter('','my_arr',$arr);
Now I want to use all its elements in XSL, and check which ids are coming in partners_id. Based on those ids, I want to show xml pages
<xsl:copy-of select="document('dashboard.h1.xml')/*"/>
<xsl:copy-of select="document('dashboard.h2.xml')/*"/>
etc.
can anyone guide?
Thanks in Advance.

Categories