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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:36:39+00:00 2026-06-10T14:36:39+00:00

Is it possible to define the following data sructure in PHP? typedef struct {

  • 0

Is it possible to define the following data sructure in PHP?

typedef struct
{
  int maxrank;          
  float rankrat[maxpop];
  int rankno[maxpop]; 
  individual ind[maxpop],
    *ind_ptr; 
}population ; 

population pop;
  • 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-10T14:36:41+00:00Added an answer on June 10, 2026 at 2:36 pm

    You can’t define a data structure other than a class in PHP, so you can always do that. It would look a little something like this:

    class Population
    {
        public $maxrank;
        public $rankrat = array();
        public $rankno = array();
        public $ind = array();
        public $ind_ptr;
    }
    
    $population = new Population();
    

    Looking a bit more at the data structure, you’d also want an Individual class, which would be referenced from $population->ind_ptr and $population->ind[]. Just remember, PHP is loosely typed, so your $ind_ptr can just as well become an array, string or whatever else instantly. A quick way around this would be with a type-hinted setter method (and subsequent getter) like this:

    protected $_ind_ptr;
    public function setIndPtr(Individual $ind)
    {
        $this->_ind_ptr = $ind;
    }
    public function getIndPtr()
    {
        return $this->_ind_ptr;
    }
    

    Alternatively, use an array to define it if it’s only in one location.

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

Sidebar

Related Questions

Is is possible to define a macro BREF(...): struct bits { int b0:1; int
Given the following structure: struct nmslist_elem_s { nmptr data; struct nmslist_elem_s *next; }; typedef
Is it possible in the following scenario to define dedicated constructors for certain specializations
How is the following possible: void contains(LinkedHashSet data, Object arg) { System.out.println(data.getClass()); // java.util.LinkedHashSet
Consider the following example: struct MyStruct { int a; int b; }; I can
I have the following store: Ext.define('Sencha.model.MenuPoint', { extend: 'Ext.data.Model', config: { fields: [ {name:
I have created an enumerated data type to define possible flight lengths. I'd like
Possible Duplicate: Define a method that has many (or infinite) arguments I have the
Possible Duplicate: Is it possible to define enumalpha? Is there any equivalent of Java
Is it possible to define a binding between an exchange (direct or topic) and

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.