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

  • SEARCH
  • Home
  • 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 8141327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:28:06+00:00 2026-06-06T12:28:06+00:00

Line 3 of the code below fails if I omit the => $v portion.

  • 0

Line 3 of the code below fails if I omit the => $v portion. I get the following error:

Warning: Illegal offset type in /home/site/page.php on line 404

When the [$k] in line 5 is changed to ['$k'], i receive the following error.

Notice: Undefined index: $k in /home/site/page.php on line 404

When it is like below with the the full $k => $v everything works though. I don’t even use $v. Why do I need it in the foreach loop to make it work then?

<? if ( $arr[ 'status'][ 'chain'] ) { 
     foreach ( $arr[ 'status'][ 'chain'] as $k => $v) { ?>
        <tr>
            <td class="line_item_data status_td">
                <?= $ arr[ 'status'][ 'chain'][$k][ 'message'] ?>
            </td>
            <td align="center">
                <img src="images/green_check.gif" width="20" />
            </td>
        </tr>
    <? } 
} ?>

I did see this answer, but don’t know that it really applies. Thanks so much!

  • 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-06T12:28:08+00:00Added an answer on June 6, 2026 at 12:28 pm

    The construct $k => $v is used to iterate an array’s keys and values in a foreach construct. You can iterate using the values $v alone, but you cannot iterate over the keys alone $k. If you used the following:

    foreach ($arr['status']['chain'] as $k)
    

    …the foreach loop is syntactically valid but $k would be populated with the array value rather than the key. In that case, the array element $ arr[ 'status'][ 'chain'][$k][ 'message'] does not exist since $k does not hold a key valid in the array $arr['status']['chain'].

    However, this can be much simpler…

    Inside the loop, $v holds the array element you are attempting to index, so you merely need to access it as:

    <?= $v['message'] ?>
    

    That is the equivalent of $arr['status']['chain'][$k]['message']. So ultimately it isn’t $v that you don’t need in your loop, but rather it is $k you don’t need.

     // Iterate the values only. Keys aren't actually needed.
     foreach ( $arr[ 'status'][ 'chain'] as $v) {
         // snip html markup..
                <?= $v[ 'message'] ?>
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With the following code below, There is an error saying File /home/user/web_pro/info/views.py, line 184,
The code below fails on the line: Class.forName(oracle.jdbc.driver.OracleDriver); with the error: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver The
For some reason, the code below fails on the second line with run-time error
Executing the below code gives me the following exception on the last line: InvalidOperationException:
can anyone explain why the code below fails? type TIDEThemeObserverFunc = reference to procedure(foo:
I have the line of code below... How would I modify it to insert
The code below produces a NumberFormatException in this line: val cache = cf.createCache(Collections.emptyMap()) Do
What does this line (x = n & 5;) mean in the code below?
The code pasted below gets an exception on the line that says... InputStream in
Below I have a line of code where it states which Session a user

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.