Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 12 of 13 · PHP Basics & Syntax
Interview question

What is the difference between indexed and associative arrays in PHP? PHP में indexed और associative arrays में क्या अंतर है?

Answer

Short Answer

A comparison table in HTML is created using standard table tags: <table>, <thead>, <tr> (rows), <th> (headers), and <td> (data cells).

Code Example

Comparison tables typically have the features listed in the left column, and the items being compared in the subsequent columns.


<table border="1">
    <thead>
        <tr>
            <th>Feature</th>
            <th>Product A</th>
            <th>Product B</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><strong>Price</strong></td>
            <td>$10</td>
            <td>$20</td>
        </tr>
        <tr>
            <td><strong>Storage</strong></td>
            <td>50 GB</td>
            <td>Unlimited</td>
        </tr>
    </tbody>
</table>
टाइपkeysउदाहरण
Indexed arrayऑटोमैटिक न्यूमेरिक keys (0,1,2...)$fruits = ["Apple","Mango"];
Associative arrayकस्टम named keys$user = ["name"=>"Raj","age"=>25];
Multidimensionalarray के अंदर array$users = [["name"=>"Raj"],["name"=>"Amit"]];

आम array फंक्शन्स: array_map(), array_filter(), array_reduce(), array_merge(), in_array(), array_keys(), array_search()

foreach ($user as $key => $value) {\n    echo "$key: $value";\n}

इंटरव्यू टिप: बताएं कि PHP array अंदर से ordered map होते हैं — "indexed" array भी टेक्निकली integer keys वाला associative array है।

Was this answer clear?