vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Array Inside of an Array? (https://vborg.vbsupport.ru/showthread.php?t=208178)

Jaxel 03-13-2009 05:10 AM

Array Inside of an Array?
 
Okay... lets say I have 2 variables...

$names[50] = 'Jaxel'
$players[3] = 50

Shouldn't therefore...

$names[$players[3]] = 'Jaxel' ?

I am trying to do this, but I am getting an error...

Warning: Illegal offset type in [path]

How do I do something like this?

TigerC10 03-13-2009 07:23 AM

Not quite... I think you want an associative array, as opposed to a nested array.

Code:

$players = array(
    "Jaxel" => 50,
    "Tiger" => 30,
);

You then access like so...
$players["Jaxel"] = 50

Nested arrays (like your example) are matrices. Grids, like checker boards...

[ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ]

You make the vertical variable, and the horizontal variable...

Consider the multiplication tables...
Vertical = X
Horizontal = Y

x=1|[1][2][3][04][05][06][07]
x=2|[2][4][6][08][10][12][14]
x=3|[3][6][9][12][15][18][21]

And you access them like this...

$mutliplicationTable[2][3] == 6


So maybe your example would be better like this
$names[50][3] = 'Jaxel'

But it's pointless to do that if you only have 1 number for each thing. Otherwise you're just wasting a lot of spaces in a row on the table. That's why it might be better (for your example) to use an associative array. Can you dig it?


All times are GMT. The time now is 06:28 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01437 seconds
  • Memory Usage 1,706KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete