associative-array

How to remove few strings from each associative array element containing a string in following situation?

一个人想着一个人 提交于 2019-12-08 13:41:42
问题 I'm having an associative array named $questions . For your reference I'm printing out first four elements from this array. The actual array is quite large but all the array elements are similar as the elements printed below: Array ( [0] => Array ( [question_id] => 33185 [question_parent_id] => 0 [question_subject_id] => 4 [question_topic_id] => 503 [question_directions] => [question_text] => Two gases are at 300 K and 350 K respectively Ratio of average kinetic energy of their molecules is

How to check if PHP associative arrays are equal, ignoring key ordering?

 ̄綄美尐妖づ 提交于 2019-12-08 08:05:57
问题 Say I have two complex nested arrays in PHP, like these: $a = array( "x" => array(4, 5, 6), "y" => array("z" => "foo", "q" => "bar") ); $b = array( "y" => array("q" => "bar", "z" => "foo"), "x" => array(4, 5, 6) ); (In this case, they're decoded JSON data from different sources). Assume the contents can be arbitrarily nested, but will not contain any circular references. What's the most straightforward way to check if they are equal, ignoring key ordering? For example, the above two should

use preg_replace to replace whole words using associative array

对着背影说爱祢 提交于 2019-12-08 07:53:09
问题 I have this replacement array named $initialdata : array ($initialdata) 'd' => string '1.40' (length=4) 'a' => string '1.67' (length=4) 'vi' => string '0' (length=1) 't' => string '?' (length=1) Then I have this string : $str = "-(vi + sqrt(2*a*d + vi^2))/a)"; When I do : str_replace(array_keys($initialdata),array_values($initialdata),$str); I Get : -(0 + sqr?(2*1.67*1.40 + 0^2))/1.67) What happened was that the "t" of the "sqrt" was replaced by the value of "t" on my $initialdata array. I

Is It Possible to Declare Constant with Associative Array [duplicate]

我怕爱的太早我们不能终老 提交于 2019-12-08 05:44:00
问题 This question already has answers here : PHP Constants Containing Arrays? (21 answers) Closed 2 years ago . I am trying to declare a constant for our office names of each country with associative array. My declaring code is as below: define( "OUR_OFFICE", [ "Japan" => "Tokyo Shibuya Office", "Taiwan" => "Taipei Shilin Office", "Korea" => "Seoul Yongsan Office", "Singapore" => "Singapore Novena Office", "Australia" => "Sydney Darlinghurst Office" ]); However, it just shows message: Warning:

Multidimensional associative array with id

梦想与她 提交于 2019-12-08 05:18:45
问题 i would like to create a array of 3 dimensions from 3 mysql tables( sections (id,title) => rubriques (id,title) => category (id,title): [0] section_title_1 section id 1 [0] rubrique_title_1 rubrique id 1 [0] category_title_1 category id 1 [1] category_title_2 category id 2 [2] ........................ [1] rubrique_title_2 rubrique id 2 ................... [1] section_title_2 ......... here is my code WITHOUT id: $output = array(); $sections = $this->_model->get_table_sections(); foreach(

How to get the keys and values of an associative array indirectly in Bash?

百般思念 提交于 2019-12-08 04:28:23
问题 In Bash, given only a variable that contains the name of an associative array, $ declare -A dict=([abc]=125 [def]=456) $ dictvar="dict" how can we retrieve the keys and values of the associative array? 回答1: In Bash, to get keys of an associative array via indirection, given the name of the array in variable dictvar one can leverage declare or local (original source): $ declare -a 'keys=("${!'"$dictvar"'[@]}")' # or 'local' Then, to get the values $ for key in ${keys[@]}; do $ value_var="$

How to initialize a matrix in plsql

北城以北 提交于 2019-12-08 04:23:56
问题 I've tried to Map a table with associative arrays , but i can't figure out how to initialize it here is an example : TYPE RecType IS RECORD ( value1 NUMBER, value2 NUMBER, value3 NUMBER ); TYPE TblType IS TABLE OF RecType INDEX BY PLS_INTEGER; TYPE TblOfTblType IS TABLE OF TblType INDEX BY PLS_INTEGER; matrix TblOfTblType; Now when i tried to initialize the matrix like this : FOR i IN matrix.FIRST .. matrix.LAST LOOP FOR j IN matrix (i).FIRST .. matrix (i).LAST LOOP matrix(i)(j) := NULL; END

PHP display associative array in HTML table

99封情书 提交于 2019-12-07 20:35:18
问题 Here is my associative array: $req_data1[]=array( 'depart1'=>$_REQUEST['to'], 'd_time1'=>$d_time5, 'stop'=>"", 'leave_stop'=>"", 'arrival1'=>$_REQUEST['from'], 'a_time1'=>$end_time5, 'price1'=>intval($final_price), 'air_line'=>"xxxxx"); Here is my sorting algorithm: foreach ($req_data as $key => $row) { $depart[$key] = $row['depart']; $d_time[$key] = $row['d_time']; $stop[$key] = $row['stop']; $leave_stop[$key] = $row['leave_stop']; $arrival[$key] = $row['arrival']; $a_time[$key] = $row['a

How to merge/combine two values into single key in the same array

半腔热情 提交于 2019-12-07 16:31:23
问题 I am not sure what is the appropriate terms to use for my title but just wondering to have below solution where need to merge/combine two values into one within a associative array. For example I have this array: Array ( [1] => Array ( [agent_name_1] => Agent 1 [agent_phone_1] => 0123456 [agent_company_1] => My Company [agent_email_1] => agent@yahoo.com [agent_address_1] => United States ) ) Here I would like to combine company_1 with address_1 . So the output should be like this: Array ( [1]

use preg_replace to replace whole words using associative array

依然范特西╮ 提交于 2019-12-07 13:45:28
I have this replacement array named $initialdata : array ($initialdata) 'd' => string '1.40' (length=4) 'a' => string '1.67' (length=4) 'vi' => string '0' (length=1) 't' => string '?' (length=1) Then I have this string : $str = "-(vi + sqrt(2*a*d + vi^2))/a)"; When I do : str_replace(array_keys($initialdata),array_values($initialdata),$str); I Get : -(0 + sqr?(2*1.67*1.40 + 0^2))/1.67) What happened was that the "t" of the "sqrt" was replaced by the value of "t" on my $initialdata array. I know that this happens because I'm using str_replace , and I need to match whole words using preg_replace