php中的键和值

时间:2016-12-18 13:28:42

标签: php arrays

我已经有一段时间了,因为我正在寻找一些东西,我被阻止了一段时间才知道如何从php数组中的值中获取键。

这是我开始研究的数组:

[It] => z
[is] => h
[soon] => y
[the] => c
[new] => w
[year] => e
[2017] => e
[!] => e

从值«y»开始,我想从另一个表中获得与键[soon](=“y”)相同的值,直到时间达到相同的值。

这是另一个数组的例子:

[Here] => a
[is] => y
[my] => c
[favorite] => u
[team] => y
[.] => o

以下是我希望从这个句子中得到的单词:

is
my
favorite

我尝试过多种方式,例如使用“in_array”但没有成功......

非常感谢那些愿意回应的人!

1 个答案:

答案 0 :(得分:1)

根据我的理解,你以某种方式从第一个数组中找到'y'字符,然后从第二个数组中过滤出键,其值以y开头和结尾。

假设您已经知道搜索参数(即y),请尝试以下操作:

RemoteViews contentView = new RemoteViews(getPackageName(), resources.getIdentifier("coreLayout", "layout", packageName));
contentView.setInt(resources.getIdentifier("coreLayout", "id", packageName),"setBackgroundColor", Color.parseColor(background_color));

NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(context)
                .setWhen(System.currentTimeMillis())
                .setContentTitle(Html.fromHtml(extras.getString(TITLE)))
                .setTicker(Html.fromHtml(extras.getString(TITLE)))
                .setContentIntent(contentIntent)
                .setAutoCancel(true)
                .setContent(contentView);

输出:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/coreLayout"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is a test notification"
        android:id="@+id/description"
        android:scrollbars="vertical"
        android:layout_gravity="fill_vertical"
        android:layout_weight="1"/>

</LinearLayout>