associative-array

Move element from one array to another [closed]

青春壹個敷衍的年華 提交于 2019-12-13 20:04:32
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I have this array: $arr1 = array( '76' => '1sdf', '43' => 'sdf2', '34' => 'sdf2', '54' => 'sdfsdf2', '53' => '2ssdf', '62' => 'sfds' ); What I want to do is take the first 3 elements, remove them and create a new array with them. So you would have this: $arr1 = array( '54' => 'sdfsdf2', '53' => '2ssdf', '62' =>

Passing an associative array as a parameter between packages

纵饮孤独 提交于 2019-12-13 16:06:55
问题 I've got two separate Oracle (v9.2) PL/SQL packages and I'm trying to pass an associative array (ie, index-by table) from a procedure in package1, as a parameter to a procedure in package2. Is this possible? I keep getting PLS-00306: wrong number or types of arguments in call to 'ROLLUP_TO_15' when I compile package1. The array is defined as: type list_tab is table of number(10) index by binary_integer; in both package's spec. In the procedure in package1, I'm calling the second package as

multidimensional array

浪尽此生 提交于 2019-12-13 15:05:50
问题 Is there a way to access a multidimensional array from any position? example: $arr = array ( 1 => array ( 1, 'some-url-one', 'Some Title One' ), 2 => array ( 2, 'some-url-two', 'Some Title Two' ), 3 => array ( 2, 'some-url-three', 'Some Title Three' ), ); Then, if we have the id of an item, for example 2 and want to get the title of that item we simply use: $title = $arr[2][2]; // which outputs Some Title Two And if we want to get the url of that same item we simply use: $title = $arr[2][1];

Remove dupes/sort from a Array of Associative Arrays in PHP

ⅰ亾dé卋堺 提交于 2019-12-13 13:41:18
问题 I have a array of associative arrays aa[] = ('Tires'=>100, 'Oil'=>10, 'Spark Plugs'=>4 ); aa[] = ('Tires'=>454, 'Oil'=>43, 'Spark Plugs'=>3 ); aa[] = ('Tires'=>34, 'Oil'=>55, 'Spark Plugs'=>44 ); aa[] = ('Tires'=>454, 'Oil'=>43, 'Spark Plugs'=>45 ); aa[] = ('Tires'=>34, 'Oil'=>55, 'Spark Plugs'=>433 ); aa[] = ('Tires'=>23, 'Oil'=>33, 'Spark Plugs'=>44 ); Two Questions How can I remove duplicates according tot he field 'Oil' is there a array_unique which I can provide a callback which acts as

Associative array without toString, etc

扶醉桌前 提交于 2019-12-13 12:10:01
问题 I want to create an associative array: var aa = {} //equivalent to Object(), new Object(), etc... and I want to be sure that any key I access is going to be a number: aa['hey'] = 4.3; aa['btar'] = 43.1; I know JS doesn't have typing, so I can't automatically check this, but I can ensure in my own code that I only assign strings to this aa. Now I'm taking keys from the user. I want to display the value for that key. However, if the user gives me something like "toString", he'll get back a

Convert associative array to indexed array with associative subarrays

不问归期 提交于 2019-12-13 10:41:46
问题 I have a simple associative array with country data like this: $array = array('country1' => CountryOne, 'country2' => Country Two); How can I dynamically transform this array in a multiple array like: array(2) { [0] => array(2) { ["code"] => "country1", ["name"] => "CountryOne" } [1] => array(2) { ["code"] => "country2", ["name"] => "CountryTwo" } } 回答1: Simply loop through it and create a new array from each key/value pair. <?php $array = array("country1" => "CountryOne", "country2" =>

Find all items with the same key in array and combine them in a new one

北慕城南 提交于 2019-12-13 10:30:10
问题 Let's suppose we have a multidimensional array like below: $obj = array ( array("carName"=>"Volvo","carColor"=>"Red", "carSpeed"=> "100 mph"), array("carName"=>"Volvo","carColor"=>"Blue", "carSpeed"=> "100 mph"), array("carName"=>"BMW","carColor"=>"White", "carSpeed"=> "120 mph"), array("carName"=>"BMW","carColor"=>"Grey", "carSpeed"=> "120 mph") ); How can I combine the "carColor" of every "carName" in a single array so that I get: $newObj = array ( array("carName"=>"Volvo","carColor"=>

Create an associative array from a string

折月煮酒 提交于 2019-12-13 09:55:14
问题 got a collection of objects which have an item called path, which has a kind of folding set by a string like: $path = '/some/sub/any/path/' now I need to create an array from that string like: array( 'some'=>array( 'sub'=>array( 'objects'=>array( array('id'=>1), array('id'=>4) ), 'any'=>array( 'path'=>array( 'objects'=>array( array('id'=>2), array('id'=>3) ) ) ) ) ) ); Actually I am looking for the best practice. Any Idea, how to solve this in PHP? 回答1: How about this? The function adds your

PHP: How do I combine multiple associative arrays into a multidimensional array?

。_饼干妹妹 提交于 2019-12-13 07:47:01
问题 Consider three associative arrays in php: $a1 = array( "a" => "1", "b" => "2", "c" => "3" ); $a2 = array( "d" => "4", "e" => "5", "f" => "6" ); $a3 = array( "g" => "7", "h" => "8", "i" => "9" ); How would you efficiently combine these into a multidimensional array as follows: $result = array( "1" => array("4","7"), "2" => array("5","8"), "3" => array("6","9") ); Thanks in advance! 回答1: Very similar to a couple of questions I answered last night: $a1 = array( "a" => "1", "b" => "2", "c" => "3"

How to convert CSV String to Associative array in PHP

女生的网名这么多〃 提交于 2019-12-13 05:50:03
问题 Almost similar questions are repeated. I am updating and fetching string from database for different issues. lets say after fetching value from database one of my variable $str looks like one of the below $str = "1:1,2:1,3:2,5:6"; or $str = "1|1,2|1,3|2,5|6"; or $str = "1=1,2=1,3=2,5=6"; how can I convert anyone or almost different string to an associative array in PHP thanks in advance. I tried for an answer but didnt find anything similar. code i tried to make it an associative array