简体   繁体   English

php 数组代码在本地主机上工作但在服务器上不工作

[英]php array code working on localhost but not working on the server

The array is working fine on local machine and loops through the images but it fails to work on the aws server.该阵列在本地机器上工作正常并循环通过图像,但它无法在 aws 服务器上工作。 It says "Trying to access array offset on value of type null".它说“尝试访问 null 类型值的数组偏移量”。

<?php              
                   $image1 = get_field('add_image');  
                   $image2 = get_field('add_image2');  
                   $image3 = get_field('add_image3');  
                   $images = array($image1, $image2, $image3);  
                   
     
 ?>
<?php $count = 0;  ?>
<?php foreach($images as $value):  ?> 
     <img src="<?php echo esc_url($value['url']); ?>" class="d-block w-100 wrap-image-single responsive " alt="..."> </a>
<?php $count++; endforeach;  ?> 

You may wish to try some basic debug...您可能希望尝试一些基本的调试...

  1. Check that image1,2,3 all have values eg var_dump($image1)检查 image1,2,3 是否都有值,例如var_dump($image1)
  2. Try and dump the $images array and see what you have.尝试转储$images数组,看看你有什么。 Do you in fact have the 'url' key on each sub-array?您实际上在每个子阵列上都有“url”键吗?

This might be a minor issue.这可能是一个小问题。 Here is my process of debugging the issue:这是我调试问题的过程:

  1. Please check that you are using valid names like add_image2, add_images3 for the function get_field请检查您是否为 function get_field 使用了有效的名称,例如add_image2, add_images3 get_field
  2. Another silly mistake might be that you would be making changes in one file and seeing the results on another file.另一个愚蠢的错误可能是您将在一个文件中进行更改并在另一个文件中查看结果。
  3. Also, make sure that you have the updated code on AWS.此外,请确保您在 AWS 上拥有更新的代码。

These are my two cents.这是我的两分钱。 Let me know how it goes.. :)让我知道事情的后续.. :)

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

相关问题 PHP代码可在localhost上运行,但不能在服务器上运行 - PHP code working on localhost but not on server 本地主机中的PHP代码在服务器中不起作用-使用phantomjs - PHP code in localhost not working in server - with phantomjs 数组在localhost中工作,但不在服务器上 - array working in localhost but not on server PHP地理编码正在本地主机上运行,​​但不在服务器上运行 - PHP geocode is working on localhost but not on server php不在localhost上工作但在web服务器上工作? - php not working on localhost but on web server? PHP 中的填字游戏代码在本地主机中不起作用 - Crossword code in PHP is not working in localhost php 代码在 xampp 本地主机上运行良好,但在实时服务器上运行不正常 - php code works fine on xampp localhost but not working on live server 强制文件下载代码在本地主机上工作,但在 php 中的实际服务器上不工作 - force file download code work on localhost but not working on actual server in php PHP cURL在本地主机上运行,​​但在服务器上不运行 - PHP cURL working in localhost but not working on Server PHP映像上传在localhost上运行,但在服务器上不运行 - PHP image upload is working on localhost but not working on server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM