PHP data structures

String:

求字符串长度:strlen();

将字符串转换为大写:strtoupper();

将字符串转换为小写:strtolower();

句首大写:ucfirst();

单词开头大写:ucwords();

           $string1="I love PHP";
           $len=strlen($string1);//求字符串的长度结果是10
           $up=strtoupper($string1);//将字符串转换为大写,结果是:I LOVE PHP
           $low= strtolower($string1);//将字符串转换为小写,结果是: i love php
           $name="harry potter";
           $name1= ucfirst($name);//将句子的首字母大写,结果是: Harry potter
           $firstname= ucwords($name);//将单词的首字母大写,结果是:Harry Potter

字符串替换:

$sentence="Today is wonderful. I don't have class.";
$change1=str_replace(' ','',$sentence);//结果是:Todayiswonderful.Idon'thaveclass
$change2= str_replace(' ','***',$sentence);//结果是:Today***is***wonderful.***I***don't***have***class.

对字符串进行分割:

$sentence="Today is wonderful. I don't have class.";
$words= explode(' ',$sentence);
print_r($words);//结果如下:
//Array ([0] => Today [1] => is [2] => wonderful. [3] => I [4] => don't [5] => have [6] => class.)

Arrays:

 Indexed arrays:

创建:

$book1=array(1,2,3,4);
$book2=[1,2,3,4];

增加:

array_push($book1,5);
$book2[]=5;
//在末尾插入5

删除、替换、排序:

array_pop($book1);//删除末尾元素
$book1[0]=1024;//替换
sort($book1);//排序

Associative arrays:

创建、添加、替换:

//创建book1 book2
$book1=["title"=>"Harry Port"];
$book2["title"]="The problem people faced today";

//book1 添加键值对
$book1["author"] ="Powers";

//将book1的键值对替换
$book1["title"]="C++ learning"

Multidimensional arrays:

创建:

$book1=["title"=>"Harry Port"];
$book2["title"]="The problem people faced today";
$books=[$book1,$book2]
//books就是Multidimensional arrays

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PHP 7 Data Structures and Algorithms by Mizanur Rahman English | 6 Jun. 2017 | ASIN: B01IF7NLDW | 340 Pages | AZW3 | 2.55 MB Key Features Gain a complete understanding of data structures using a simple approach Analyze algorithms and learn when you should apply each solution Explore the true potential of functional data structures Book Description PHP has always been the the go-to language for web based application development, but there are materials and resources you can refer to to see how it works. Data structures and algorithms help you to code and execute them effectively, cutting down on processing time significantly. If you want to explore data structures and algorithms in a practical way with real-life projects, then this book is for you. The book begins by introducing you to data structures and algorithms and how to solve a problem from beginning to end using them. Once you are well aware of the basics, it covers the core aspects like arrays, listed lists, stacks and queues. It will take you through several methods of finding efficient algorithms and show you which ones you should implement in each scenario. In addition to this, you will explore the possibilities of functional data structures using PHP and go through advanced algorithms and graphs as well as dynamic programming. By the end, you will be confident enough to tackle both basic and advanced data structures, understand how they work, and know when to use them in your day-to-day work What you will learn Gain a better understanding of PHP arrays as a basic data structure and their hidden power Grasp how to analyze algorithms and the Big O Notation Implement linked lists, double linked lists, stack, queues, and priority queues using PHP Work with sorting, searching, and recursive algorithms Make use of greedy, dynamic, and pattern matching algorithms Implement tree, heaps, and graph algorithms Apply PHP functional data structures and built-in data structures and algorithms About the Autho
Rust数据结构是指在Rust编程语言中可以用于存储和组织数据的不同方式和类型。Rust提供了许多内置的数据结构,同时也可以使用各种第三方库来扩展这些数据结构。 常见的Rust数据结构包括: 1. 向量(Vectors):向量是一个动态长度的数组,可以在其中存储任意类型的数据。向量可以动态增长或缩小,也可以按索引访问元素。 2. 哈希映射(Hash Maps):哈希映射是一种键值对的数据结构,其中每个键都与一个唯一的值相关联。哈希映射的插入和查找操作的时间复杂度通常为O(1),因此在需要快速查找或数据去重的场景中非常有用。 3. 字符串(Strings):Rust中的字符串是一系列Unicode标量值的集合。它们可以通过字面量、转换或动态构建来创建和操作。Rust还提供了许多与字符串相关的方法和操作符。 4. 切片(Slices):切片是对数组或向量的引用,允许您引用整个集合或仅引用集合的一部分。切片非常适用于通过传递指定范围的数据来减少内存占用和提高性能的情况。 此外,还有很多其他数据结构可以在Rust中使用,例如堆栈、队列、链表等。Rust还提供了许多强大的工具和概念,如所有权、借用和生命周期,这些可以帮助开发人员安全地管理数据结构的访问和修改。 通过使用各种数据结构,Rust为开发人员提供了灵活和高效的方式来存储和操作数据,使他们能够更轻松地构建稳健和高性能的应用程序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值