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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:01:46+00:00 2026-06-15T15:01:46+00:00

HI I am fairly new to php. I have an array $arr = array(0

  • 0

HI I am fairly new to php.

I have an array

$arr = array(0 => array(‘GID’=>1,’groupname’=>”cat1″,’members’=>array(0=>array(‘mid’=>11,’mname’=>’wwww’),1=>array(‘mid’=>12,’mname’=>’wswww’))),
1 => array(‘GID’=>2,’groupname’=>”cat2″,’members’=>array(0=>array(‘mid’=>13,’mname’=>’gggwwww’),1=>array(‘mid’=>14,’mname’=>’wvvwww’))),
2 => array(‘GID’=>3,’groupname’=>”cat1″,’members’=>array(0=>array(‘mid’=>15,’mname’=>’wwddsww’)),1=>array(‘mid’=>16,’mname’=>’wwwdddw’)));

      ie...,I have GID,groupname,mid(member id),mname(member name).I want to insert a new mid and mname into a group if it is already in the array ,if it is not exists then create a new subarray with these elements..I also need to check a member id(mid) is also present.........................I used the code but its not working fine............. if (!empty($evntGroup)) {


            foreach ($evntGroup as $k => $group) {

                if ($group['GID'] == $group_id) {
                    foreach($group as $j=> $mem){

                    if($mem['mid'] == $mem_id){

                        unset($evntGroup[$k]['members'][$j]['mid']);
                        unset($evntGroup[$k]['members'][$j]['mname']);
                    }
                    else{


                    $evntGroup[$k]['members'][] = array(
                        'mid' => $mem_id,
                        'mname' => $mem_name);

                    }}
                } else {


                    $evntGroup[] = array(
                        'GID' => $group_id,
                        'groupname' => $Group['event_group_name'],
                        'members' => array(
                            0 => array(
                                'mid' => $mem_id,
                                'mname' => $mem_name
                            )
                        )
                    );

                }

            }
        } else {

            $evntGroup[$i]['GID'] = $group_id;
            $evntGroup[$i]['groupname'] = $Group['event_group_name'];
            $evntGroup[$i]['members'][] = array(
                'mid' => $mem_id,
                'mname' => $mem_name);
            $i++;

        }
  • 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-15T15:01:47+00:00Added an answer on June 15, 2026 at 3:01 pm

    In the form of a function, the easiest solution will look something like this:

    function isGidInArray($arr, $val) {
        foreach($arr as $cur) {
            if($cur['GID'] == $val)
                return true;
        }
        return false;
    }
    

    You’ve updated your question to specify what you want to do if the specified GID is found, but that’s just a trivial addition to the loop:

    function doSomethingIfGidInArray($arr, $val) {
        foreach($arr as $cur) {
            if($cur['GID'] == $val) {
                doSomething();
                break; //Assuming you only expect one instance of the passed value - stop searching after it's found
            }
        }
    }
    

    There is unfortunately no native PHP array function that will retrieve the same index of every array within a parent array. I’ve often wanted such a thing.

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

Sidebar

Related Questions

I am fairly new to php and mysql but I have created a small
I am fairly new to PHP, but have applied my previous knowledge of programming,
I am fairly new to PHP OOP, the problem that I am have is
I have plenty of experience with this in PHP, but am fairly new to
I'm fairly new to php and was wondering how do I validate the array
I am fairly new to php and have not figured out how I would
I'm fairly new to PHP so I have a small problem as I'm learning:
I'm fairly new to PHP and have been using PHP's readdir() to look into
fairly new to Objective-C and iOS development (coming from PHP) and I have a
I am fairly new to codeigniter. I have the following code in my views/check_availability/index.php

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.