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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:08:18+00:00 2026-05-15T04:08:18+00:00

I have an array that looks similar to this, [4] => Common_Model Object (

  • 0

I have an array that looks similar to this,

[4] => Common_Model Object
    (
        [id] => 4
        [name] => 
        [date_created] => 
        [last_updated] => 
        [user_id_updated] => 
        [_table] => 
        [_aliases] => Array
            (
                [id] => 4
                [name] => 
                [date_created] => 
                [date_updated] => 
                [user_id_updated] => 
                [rating] => 3
                [recipe_id] => 5
            )

        [_nonDBAliases] => Array
            (
            )

        [_default] => Array
            (
            )

        [_related] => Array
            (
            )

        [_enums] => 
        [_alsoDelete] => Array
            (
            )

        [_readOnly] => Array
            (
                [0] => date_updated
            )

        [_valArgs] => Array
            (
            )

        [_valArgsHash] => Array
            (
                [default] => Array
                    (
                    )

            )

        [_valAliases] => Array
            (
            )

        [_extraData] => Array
            (
            )

        [_inputs] => Array
            (
            )

        [_tableName] => jm_ratings
        [_tablePrefix] => 
        [_niceDateUpdated] => 1st Jan 70
        [_niceDateCreated] => 1st Jan 70
        [_fetchAdminData] => 
        [_mCache] => 
        [_assets] => Array
            (
            )

    )

[3] => Common_Model Object
    (
        [id] => 3
        [name] => 
        [date_created] => 
        [last_updated] => 
        [user_id_updated] => 
        [_table] => 
        [_aliases] => Array
            (
                [id] => 3
                [name] => 
                [date_created] => 
                [date_updated] => 
                [user_id_updated] => 
                [rating] => 1
                [recipe_id] => 5
            )

        [_nonDBAliases] => Array
            (
            )

        [_default] => Array
            (
            )

        [_related] => Array
            (
            )

        [_enums] => 
        [_alsoDelete] => Array
            (
            )

        [_readOnly] => Array
            (
                [0] => date_updated
            )

        [_valArgs] => Array
            (
            )

        [_valArgsHash] => Array
            (
                [default] => Array
                    (
                    )

            )

        [_valAliases] => Array
            (
            )

        [_extraData] => Array
            (
            )

        [_inputs] => Array
            (
            )

        [_tableName] => jm_ratings
        [_tablePrefix] => 
        [_niceDateUpdated] => 1st Jan 70
        [_niceDateCreated] => 1st Jan 70
        [_fetchAdminData] => 
        [_mCache] => 
        [_assets] => Array
            (
            )

    )

[2] => Common_Model Object
    (
        [id] => 2
        [name] => 
        [date_created] => 
        [last_updated] => 
        [user_id_updated] => 
        [_table] => 
        [_aliases] => Array
            (
                [id] => 2
                [name] => 
                [date_created] => 
                [date_updated] => 
                [user_id_updated] => 
                [rating] => 1
                [recipe_id] => 5
            )

        [_nonDBAliases] => Array
            (
            )

        [_default] => Array
            (
            )

        [_related] => Array
            (
            )

        [_enums] => 
        [_alsoDelete] => Array
            (
            )

        [_readOnly] => Array
            (
                [0] => date_updated
            )

        [_valArgs] => Array
            (
            )

        [_valArgsHash] => Array
            (
                [default] => Array
                    (
                    )

            )

        [_valAliases] => Array
            (
            )

        [_extraData] => Array
            (
            )

        [_inputs] => Array
            (
            )

        [_tableName] => jm_ratings
        [_tablePrefix] => 
        [_niceDateUpdated] => 1st Jan 70
        [_niceDateCreated] => 1st Jan 70
        [_fetchAdminData] => 
        [_mCache] => 
        [_assets] => Array
            (
            )

    )

I wanting to add up the [rating] and get the mean average. But I dont know how do this with PHP, my attempt looks like this,

<?php  
     foreach ($rt as $rating) {
          $total = $rating->rating + $rating->rating
     }
$total / count($rt);
?>
  • 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-15T04:08:18+00:00Added an answer on May 15, 2026 at 4:08 am

    Try this:

    $total = 0;
    foreach($rt as $elem) {
        $total += $elem->_aliases['rating'];
    }
    echo sprintf("Average: %d", $total/count($rt));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array that looks like this: Array ( [0] => Array (
I have a variable that looks likes this, $rslt['expected_salary_level'] This returns a string similar
I javascript I have an object that looks similar to: var myObj = {
I have one array that contains some settings that looks like basically like this:
I have an array that I pull that looks like this: [157966745,275000353,43192565,305328212] ... How
If i have an array $output that looks like this, how can i search
I have some code that looks something like this: <? $addr = array(city =>
I have an array that looks like $numbers = array('first', 'second', 'third'); I want
I have a record that looks similar to: type TNote = record Title :
Possible Duplicate: Length of Javascript Associative Array I have a JSON that looks like

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.