PHP tips, Array Value problems!

Source: Internet
Author: User
PHP tips, Array Value problems! The number level is like this: (I picked a group of data from a large pile. In fact, I want to extract all the data and echo it to the window)
[16] => Array
(
[Option_id] => 30
[Option_name] => att_type
[Option_value] => rar, zip, gif, jpg, jpeg, png, txt, pdf, docx, doc
)


The purpose is to print the rar, zip, gif, jpg, jpeg, png, txt, pdf, docx, and doc.
Currently, we know that we can assign values using loops, but we can only use echo $ option_name to obtain the att_type value. we cannot use echo $ att_type to retrieve rar, zip, gif, jpg, jpeg, png, txt, pdf, docx, doc. Let's help me write a piece of code to realize my thoughts. let's ask for help !!!!!!


Reply to discussion (solution)

Come and save me ..........

There is something wrong with it. all arr_types are wrong. it should be att_type.

Come and save me ...........

It is difficult to help without posting code

It is difficult to help without posting code


The code is very simple, that is, first select from the database, put it in an array, and then print_r, that's it.
$ Arr = $ this-> Setting_model-> get_setting (); // $ query = $ this-> db-> get ('options '); return $ query-> result_array ();
$ This-> load-> p ($ arr); die;

The database seems to have nothing to do with this. I will not post it.

$ This-> load-> p () // public function p () {echo'

;print_r($arr);echo '
';}

However, your demand is too different and strange.

$a = array(    16 => Array        (            'option_id' => 30,            'option_name' => 'att_type',            'option_value' => 'rar,zip,gif,jpg,jpeg,png,txt,pdf,docx,doc',        ),);foreach($a as $r) {  ${$r['option_name']} = $r['option_value'];  echo $att_type;}
Rar, zip, gif, jpg, jpeg, png, txt, pdf, docx, doc

I don't know. it means no.

$arr =  Array    (            'option_id' => 30,            'option_name' => 'att_type',            'option_value' => 'rar,zip,gif,jpg,jpeg,png,txt,pdf,docx,doc'    );$a[$arr['option_name']] = $arr['option_value'];extract($a);var_dump($att_type);

However, your demand is too different and strange.

$a = array(    16 => Array        (            'option_id' => 30,            'option_name' => 'att_type',            'option_value' => 'rar,zip,gif,jpg,jpeg,png,txt,pdf,docx,doc',        ),);foreach($a as $r) {  ${$r['option_name']} = $r['option_value'];  echo $att_type;}
Rar, zip, gif, jpg, jpeg, png, txt, pdf, docx, doc


This will definitely not work. an error will be reported. The undefined att_type

I don't know. it means no.

$arr =  Array    (            'option_id' => 30,            'option_name' => 'att_type',            'option_value' => 'rar,zip,gif,jpg,jpeg,png,txt,pdf,docx,doc'    );$a[$arr['option_name']] = $arr['option_value'];extract($a);var_dump($att_type);



Error: undefined option_name, option_value... And so on. many (Undefined index: option_value)

Yes? Take it for granted ?!
I have all the running results.

I know that the extract function will certainly be used. the function is like assigning the name value to the value.

Yes? Take it for granted ?!
I have all the running results.


Capture a graph of your results. how can I run it and report an error?

However, your demand is too different and strange.

$a = array(    16 => Array        (            'option_id' => 30,            'option_name' => 'att_type',            'option_value' => 'rar,zip,gif,jpg,jpeg,png,txt,pdf,docx,doc',        ),);foreach($a as $r) {  ${$r['option_name']} = $r['option_value'];  echo $att_type;}
Rar, zip, gif, jpg, jpeg, png, txt, pdf, docx, doc



I did not understand $ {$ r ['option _ name']} = $ r ['option _ value, so we changed it to $ r ['option _ name'] = $ r ['option _ value. Sorry. This is solved, and you need to ask, $ {$ r ['option _ name']} = $ r ['option _ value']; means? I really don't understand

To be fair, I'm presenting it to you in the online editor of conengu.

Variable reading

Variable reading



What happened again !!!

To use the variable name of the array, you need to solve the ambiguity problem. That is, if you write $ a [1], the parser needs to understand whether you mean to treat $ a [1] as a variable, we still need to regard $ a as a variable. [1] refers to the index of this variable. The syntax for solving this ambiguity is: $ {$ a [1]} is used in the first case, and $ {$ a} [1] is used in the second case.

Thank you !!! Learned

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.