Passing PHP Array to XSL [closed] - php

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.

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 Count 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 6 years ago.
Improve this question
If array with 2 keys:
Array(
[0] => content
[1] => content
)
It is a task
if array 3 keys
Array(
[0] => content
[1] => content
[2] => content
)
It is other task
How count how many keys ([0], [1]..) there are in the array?
I already have all the structure of the code but just need to know how to know the amount of keys within the variable that contains the array
$len = count($myArray);
I think this is what you're asking?
As per your comment if you are using array_count_values() it will return the array that contains no of count of same values.
$yourArr = array("content","content");
print_r( array_count_values($yourArr) );
Result:
array("content"=>2);
From W3School:
Returns an associative array, where the keys are the original array's values, and the values are the number of occurrences

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 :)

How can I access the id value in this array? [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
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()..)

array declration methods in php [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 have array like this, where i have maintaining a index that is the position and there is two field which should be update
Array
(
[0] => Array
(
[text2] => Banner ads
[price2] => 297
)
)
now i want to insert another element like a way that look like
Array
(
[1] => Array
(
[text2] => logo
[price2] => 300
)
)
what would be the best way to do so??? please suggest me?
$array[] = array('text2' => 'logo', 'price2' => 300)

Categories