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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:58:47+00:00 2026-06-02T17:58:47+00:00

Imagine we have an array of students: Students: Ben Sam … Every student has

  • 0

Imagine we have an array of students:

Students: Ben Sam …

Every student has a group of books at home:

Books:

  • Sam A B C D
  • Ben D E F
  • Ryan A D G D

So in PHP, the $students data structure looks like this:

Array
(
    [0] => Array
        (
            [name] => Joe Smith
            [books] => Array
                (
                    [0] => A
                    [1] => B
                    [2] => C
                )

        )

)

We want to count how many times A has been repeated and who owns A B and C etc.
One way to do it in php is to do this:

if (sizeof($potential_entries) > 0) :
  for ($j = 0, $potentialsize = sizeof($potential_entries); $j < $potentialsize; ++$j)     {
    for ($k = 0, $listsize = sizeof($student_book); $k < $listsize; ++$k) {
      if ($student_book[$k] == $potential_entry[$k]) :
        $match = 1;
        $student_book[$k]['like_count']++;
       endif;
    }
  }

This is not very efficient we rather want a map structure or a hashtable, Does php has those structures like perl? or do we have to manually build them.
Edit:
I can see in the PHP that we have associative array? Can you please give an example of that could not find it in the documentation.
for sam:

var_dump($potential_entry):

[0]=>array(2) { ["name"]=> string(1) "A" ["id"]=> string(11) "1348"}
[1]=>array(2) { ["name"]=> string(1) "B" ["id"]=> string(11) "1483"}
[2]=>array(2) { ["name"]=> string(1) "C" ["id"]=> string(11) "13"}
[3]=>array(2) { ["name"]=> string(1) "D" ["id"]=> string(11) "1174"}

That is for Sam, for the rest we have the same structure. so sam is array and books is an array and sam has an array of books.
In this example

  • D count=3 sam ben ryan
  • A count=2 sam ryan
  • etc…
  • 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-02T17:58:48+00:00Added an answer on June 2, 2026 at 5:58 pm

    If you have $students as an array, and each entry in this array has an array of books which is called books

    $books = array(); 
    for ($i = 0, $count = sizeof($students); $i++) {
       foreach ($student[$i]['books'] as $book) { 
          if (isset($books[$book])) { 
              $books[$book]++; 
          } else { 
              $books[$book] = 1;
          }
       }
    }
    

    Then after this, any $books entry whose count is > 1 is a duplicate, i.e.

    foreach ($books as $key => $value) { 
       if ($value) > 1) { 
            echo "Book " . $key . " is a duplicate (" . $value . ")"; 
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine you have a large array of floating point numbers, of all kinds of
I’m working on a multi dimensions array but i have a problem Imagine I
i have an array of points in 3d (imagine the trajectory of a ball)
Let's imagine that we have two arrays: $array_1 = array( '0' => 'zero', '1'
Imagine I have an JS array like this: var a = [1, 2, 3,
Imagine you have an RGB image and want to process every pixel: import numpy
Imagine I have an array: A = Array(1, 2, 3, 4, 5, 6, 7,
Imagine I have a vertex array and an index array. Suppose it is possible
Imagine I have a member variable @property(nonatomic,retain)NSArray *array; Now in my viewDidLoad I set
In F#, imagine we have an array of bytes representing pixel data with three

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.