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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:11:11+00:00 2026-05-19T12:11:11+00:00

class something{ public function add_val( $val ){ $array = array(); foreach( $val as $value

  • 0
class something{   
    public function add_val( $val ){
    $array = array();
    foreach( $val as $value ) {
        $array[] = static::$post[${$value}];
    }
    return $array;
    }
    pulblic function somethingelse(){
       .... 
       ....
       $optionsArray['value'] = array_map( 'add_val', array_chunk( $drop_val, count( $optionsArray['heading_x'] ) ) );
       ....
       ....
    }
}

how can i call the add_val method within the other using array_map()??

  • 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-19T12:11:12+00:00Added an answer on May 19, 2026 at 12:11 pm

    Use an array that contains the object, and the method name:

    $optionsArray['value'] = array_map(array($this, 'add_val'), array_chunk($drop_val, count($optionsArray['heading_x'])));
    

    You do the same for most other functions that take in callbacks as parameters, like array_walk(), call_user_func(), call_user_func_array(), and so on.

    How does it work? Well, if you pass an array to the callback parameter, PHP does something similar to this (for array_map()):

    if (is_array($callback)) {         // array($this, 'add_val')
        if (is_object($callback[0])) {
            $object = $callback[0];    // The object ($this)
            $method = $callback[1];    // The object method name ('add_val')
    
            foreach ($array as &$v) {
                // This is how you call a variable object method in PHP
                // You end up doing something like $this->add_val($v);
                $v = $object->$method($v);
            }
        }
    }
    
    // ...
    
    return $array;
    

    Here you can see that PHP just loops through your array, calling the method on each value. Nothing complicated to it; again just basic object-oriented code.

    This may or may not be how PHP does it internally, but conceptually it’s the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To make a JavaScript class with a public method I'd do something like: function
Using NHibernate.Mapping.Attributes, I have a entity class with something like: [Class] public class EntityA
I have a class which looks something like this: public class Test { private
I've got a class that looks something like this: public class Parent { public
I've got a simple java class that looks something like this: public class Skin
I require a tree / directed acyclic graph implementation something like this: public class
Let's say I have data structures that're something like this: Public Class AttendenceRecord Public
I've got a object (Filter) that's defined something like this public class Filter {
I've trying to achieve something like this: class Base { public: Base(string S) {
Is it possible to have something like the following: class C { public Foo

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.