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 6613047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:10:18+00:00 2026-05-25T20:10:18+00:00

Please check my code below,it returns 0 while I am expecting a result 14.But

  • 0

Please check my code below,it returns 0 while I am expecting a result 14.But when I add A+D manually it returns 5.Am i doing something wrong inside the loop ?

<?php
    define('A',1);
    define('B',2);
    define('C',3);
    define('D',4);
    define('E',5);

    //echo A+D; returns 5

    $name = 'EACE';

    $len = strlen($name);

    for($i = 0; $i<=$len; $i++)
    {
        $val += $name[$i]; 
    }
    echo $val;   //returns 0

?>
  • 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-05-25T20:10:18+00:00Added an answer on May 25, 2026 at 8:10 pm

    You need to use constant(..) to get the value of a constant by name. Try this:

    for ($i = 0; $i < strlen($name); $i++) {
        $val += constant($name[$i]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written below code to check for blank value in my textbox but
Please check the code below, the problem is that no form element are displayed
Please check this below code. After for loop remaining code is not executing. It
Please check this code out it compiles and runs absolutely fine.. The question is
Please check my HTML below: <table cellpadding=0 cellpadding=0 border=0> <tr> <td> <div class=toogler>Demo1</div> </td>
PLEASE CHECK ANSWERS by VolkerK too, he provided another solution, but I can't mark
Please check below screen shot. What is main difference between Master Page and MVC
Below are 2 code snippets used to check if a folder exists in a
Please see the code fragment below, specifically the first 'else if' statement. I want
I wrote the below code in order to check for three files and whichever

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.