English 中文(简体)
array_splice with multidimensional arrays?
原标题:

Okay so I m fairly new to PHP and I am currently experimenting with arrays. As an example, lets assume this is my array:

    $t1 = array (
  "basicInfo" => array (
   "The Sineps",
   "December 25, 2010",
   "lemonpole_1g"
  ),
  "overallRecord" => array (
   "23",
   "12",
   "19",
   ""
  )
);

From what I could gather, I found out that the function array_splice allows me to point to a specific index in the array and add/remove data. From all of the examples that I ve seen using this function...only numeric arrays were used. Now my question is how would I point to ["overallRecord"][3](which is empty) for example, and update that field?

For further understanding that empty field is for "total points":

$wins = $t1["overallRecord"][0] * 3;
$loss = $t1["overallRecord"][1];
$draw = $t1["overallRecord"][2];
$total = $wins + $draw;

So to sum it all up, I d like to add the variable $total to ["overallRecord"][3]. It doesn t necessarily have to be with array_splice, however, if you come up with a different method to achieve this try and keep it simple or add comments please :)

Thanks in advance!

最佳回答

If I understand correctly, simply do

$t1["overallRecord"][3] = $total;
问题回答
$t1["overallRecord"][3] = $total;




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签