Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9219567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:08:44+00:00 2026-06-18T03:08:44+00:00

Possible Duplicate: PHP syntax for dereferencing function result i wrote some code in php

  • 0

Possible Duplicate:
PHP syntax for dereferencing function result

i wrote some code in php 5.4 and my server can only run 5.3,thus i have some syntax errors i need to fix.

when i got to the site I get this error

 Parse error: syntax error, unexpected '[' in /home/content/51/6663351/html/application/controllers/admin.php on line 247

line 247 is

if(count($results->result()) > 0)
            {
 this here>>>   $data['data'] = $results->result()[0];
                $data['cats'] = $this->db->get('category')->result();
                $data['curCat'] = $this->db->get('products_categories',     array('product_id' => $id))->result()[0];   

so I tried changing the code to:

 $data = array();
 if(count($results->result()) > 0)
            {
                $data['data'] = $results->result()[0];
                $data['cats'] = $this->db->get('category')->result();
                $data['curCat'] = $this->db->get('products_categories', array('product_id' => $id))->result()[0];

how ever adding the $data = array(); didn’t fix anything. Does anyone have an idea what is wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:08:45+00:00Added an answer on June 18, 2026 at 3:08 am

    This $results->result()[0] is called array dereferencing. It’s new in PHP 5.4 so you can’t do it in 5.3. You’ll need to return that array element first and then use it in your code.

    From the manual:

    <?php
    function getArray() {
        return array(1, 2, 3);
    }
    
    // on PHP 5.4
    $secondElement = getArray()[1];
    
    // previously
    $tmp = getArray();
    $secondElement = $tmp[1];
    
    // or
    list(, $secondElement) = getArray();
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: PHP syntax for dereferencing function result If a PHP function returns an
Possible Duplicate: PHP syntax for dereferencing function result Here is what I mean. Currently
Possible Duplicate: PHP syntax for dereferencing function result I have a string, which looks
Possible Duplicate: Access array returned by a function in php The code: $cnt =
Possible Duplicate: Can I use a function to return a default param in php?
Possible Duplicate: PHP function to strip tags, except a list of whitelisted tags and
Possible Duplicate: php loop through associative arrays i have this piece of code which
Possible Duplicate: PHP PDO: Can I bind an array to an IN() condition? I
Possible Duplicate: Initializing PHP class property declarations with simple expressions yields syntax error I
Possible Duplicate: Sending PHP json_encode array to jQuery I have a little function that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.