简体   繁体   English

如何从关联数组PHP获取单个值

[英]How to get a single value from an associative array PHP

When I code => 当我编码=>

if((isset($filename1))){
    print_r(array_values($filename1));
    $file_name=$filename1['file_name'];
    echo $file_name." this is file_name<br>";
    echo $filename1['file_name']."This isdirectly from the array <br>";
    }

I get the following out put and error=> 我得到以下输出和错误=>

Array ( [0] => Array ( [file_name] => uygun10.pgn [file_type] => application/x-chess-pgn [file_path] => D:/wamp/www/proje/uploads/ [full_path] => D:/wamp/www/proje/uploads/uygun10.pgn [raw_name] => uygun10 [orig_name] => uygun.pgn [client_name] => uygun.pgn [file_ext] => .pgn [file_size] => 0.48 [is_image] => [image_width] => [image_height] => [image_type] => [image_size_str] => ) )
A PHP Error was encountered

Severity: Notice

Message: Undefined index: file_name

Filename: controllers/Hesaplama.php

Line Number: 58

Backtrace:

File: D:\wamp\www\proje\application\controllers\Hesaplama.php
Line: 58
Function: _error_handler

File: D:\wamp\www\proje\application\controllers\Hesaplama.php
Line: 263
Function: pgn_oku

File: D:\wamp\www\proje\application\controllers\Welcome.php
Line: 28
Function: pozisyon_tutma

File: D:\wamp\www\proje\index.php
Line: 292
Function: require_once
this is file_name
A PHP Error was encountered

Severity: Notice

Message: Undefined index: file_name

Filename: controllers/Hesaplama.php

Line Number: 60

Backtrace:

File: D:\wamp\www\proje\application\controllers\Hesaplama.php
Line: 60
Function: _error_handler

File: D:\wamp\www\proje\application\controllers\Hesaplama.php
Line: 263
Function: pgn_oku

File: D:\wamp\www\proje\application\controllers\Welcome.php
Line: 28
Function: pozisyon_tutma

File: D:\wamp\www\proje\index.php
Line: 292
Function: require_once

When I modify the code as follows => 当我如下修改代码=>

if((isset($filename1))){
print_r(array_values($filename1));
$file_name=$filename1[0]['file_name'];
echo $file_name." this is file_name<br>";
echo $filename1[0]['file_name']."this is directly from the array <br>";
}

I get the following output and error => 我得到以下输出和错误=>

Array ( [0] => Array ( [file_name] => uygun11.pgn [file_type] => application/x-chess-pgn [file_path] => D:/wamp/www/proje/uploads/ [full_path] => D:/wamp/www/proje/uploads/uygun11.pgn [raw_name] => uygun11 [orig_name] => uygun.pgn [client_name] => uygun.pgn [file_ext] => .pgn [file_size] => 0.48 [is_image] => [image_width] => [image_height] => [image_type] => [image_size_str] => ) )
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 0

Filename: controllers/Hesaplama.php

Line Number: 58

Backtrace:

File: D:\wamp\www\proje\application\controllers\Hesaplama.php
Line: 58
Function: _error_handler

File: D:\wamp\www\proje\application\controllers\Hesaplama.php
Line: 263
Function: pgn_oku

File: D:\wamp\www\proje\application\controllers\Welcome.php
Line: 28
Function: pozisyon_tutma

File: D:\wamp\www\proje\index.php
Line: 292
Function: require_once
this is file_name
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 0

Filename: controllers/Hesaplama.php

Line Number: 60

Backtrace:

File: D:\wamp\www\proje\application\controllers\Hesaplama.php
Line: 60
Function: _error_handler

File: D:\wamp\www\proje\application\controllers\Hesaplama.php
Line: 263
Function: pgn_oku

File: D:\wamp\www\proje\application\controllers\Welcome.php
Line: 28
Function: pozisyon_tutma

File: D:\wamp\www\proje\index.php
Line: 292
Function: require_once

How can I possibly reach single items which are apparently in array $filename1...? 我怎么可能到达显然在数组$ filename1 ...中的单个项目? Thank you all 谢谢你们

I was only able to recover the single values with the below code=> 我只能使用以下代码恢复单个值=>

$filename2= $this->session->flashdata('item');
$filename1= $filename2['upload_data']['file_name'];

Where the session was created with the following code in another page=> 在另一个页面中使用以下代码创建会话的位置=>

else { 
            $data = array('upload_data' => $this->upload->data()); 
            $this->load->view('Upload_success', $data); 
         } 
            $this->session->set_flashdata('item', $data);
      }

Thanks to all responders... 感谢所有响应者...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM